update
This commit is contained in:
parent
eb5fc7aab6
commit
221fadf2ce
16
README.md
16
README.md
@ -12,7 +12,21 @@ algorithm_2024
|
|||||||
|
|
||||||
#### 未考虑无答案(特殊情况)时输出
|
#### 未考虑无答案(特殊情况)时输出
|
||||||
|
|
||||||
#### 优先对联是从大到小排序,重载运算符时需反向或者std::greater
|
#### 优先队列是从大到小排序,重载运算符时需反向或者std::greater
|
||||||
|
```cpp
|
||||||
|
for(ll i{0};i<4;i++){
|
||||||
|
const Point next {status.now.x+to_next[i][0],status.now.y+to_next[i][1]};
|
||||||
|
if(vis[next.x][next.y])continue;
|
||||||
|
const auto nextchar = [&next]()->char{return map[next.x][next.y];};
|
||||||
|
ll cost {1};
|
||||||
|
if(next.x>h || next.x<=0 || next.y > w || next.y<=0
|
||||||
|
|| nextchar()=='#')continue;
|
||||||
|
if(nextchar()=='x')cost++; // 因为这里有可能会遇到士兵,会改变最优解顺序,要使用priority_queue
|
||||||
|
const Status next_status {next,status.step+cost};
|
||||||
|
vis[next_status.now.x][next_status.now.y] = true;
|
||||||
|
q.push(next_status);
|
||||||
|
}
|
||||||
|
```
|
||||||
```cpp
|
```cpp
|
||||||
struct Status{
|
struct Status{
|
||||||
Point now;
|
Point now;
|
||||||
|
@ -57,7 +57,7 @@ void bfs(const Point start)noexcept{
|
|||||||
ll cost {1};
|
ll cost {1};
|
||||||
if(next.x>h || next.x<=0 || next.y > w || next.y<=0
|
if(next.x>h || next.x<=0 || next.y > w || next.y<=0
|
||||||
|| nextchar()=='#')continue;
|
|| nextchar()=='#')continue;
|
||||||
if(nextchar()=='x')cost++;
|
if(nextchar()=='x')cost++; // 因为这里有可能会遇到士兵,会改变最优解顺序,要使用priority_queue
|
||||||
const Status next_status {next,status.step+cost};
|
const Status next_status {next,status.step+cost};
|
||||||
vis[next_status.now.x][next_status.now.y] = true;
|
vis[next_status.now.x][next_status.now.y] = true;
|
||||||
q.push(next_status);
|
q.push(next_status);
|
||||||
|
Loading…
Reference in New Issue
Block a user