This commit is contained in:
Zengtudor 2024-10-14 13:31:57 +08:00
parent eb5fc7aab6
commit 221fadf2ce
2 changed files with 16 additions and 2 deletions

View File

@ -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;

View File

@ -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);