diff --git a/README.md b/README.md index f061f4a..80fb707 100755 --- a/README.md +++ b/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 struct Status{ Point now; diff --git a/src/oj4980/oj4980.cpp b/src/oj4980/oj4980.cpp index d8c8154..e52dd3c 100644 --- a/src/oj4980/oj4980.cpp +++ b/src/oj4980/oj4980.cpp @@ -57,7 +57,7 @@ void bfs(const Point start)noexcept{ ll cost {1}; if(next.x>h || next.x<=0 || next.y > w || next.y<=0 || nextchar()=='#')continue; - if(nextchar()=='x')cost++; + 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);