From 877f1122965b6cd431ecd37af092488a7aa0489b Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Fri, 11 Oct 2024 16:43:27 +0800 Subject: [PATCH] update --- src/P8093/P8093.cpp | 2 +- src/oj4980/oj4980.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/oj4980/oj4980.cpp diff --git a/src/P8093/P8093.cpp b/src/P8093/P8093.cpp index ef2f534..8605559 100755 --- a/src/P8093/P8093.cpp +++ b/src/P8093/P8093.cpp @@ -18,7 +18,7 @@ cal(a,b) 5)ab){ diff --git a/src/oj4980/oj4980.cpp b/src/oj4980/oj4980.cpp new file mode 100644 index 0000000..0d4e53a --- /dev/null +++ b/src/oj4980/oj4980.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include + +typedef long long ll; +auto &is = std::cin; +auto &os = std::cout; + +struct Point{ + ll x,y; +}; +struct Status{ + Point now; + ll step; + bool operator<(const Status &that)const noexcept{ + return this->step > that.step; + } +}; + +const ll max_nm {200+5}; +ll n, h, w, ans{std::numeric_limits::max()}; +char map[max_nm][max_nm]; +Point me; + +const int to_next[4][2] { + {1,0}, + {0,1}, + {-1,0}, + {0,-1}, +}; + +void bfs(const Point start)noexcept{ + std::bitset vis[max_nm]; + + std::priority_queue q; + ans = std::numeric_limits::max(); + vis[start.x][start.y] = true; + + q.push({start,0}); + while(q.empty()==false){ + const auto status = q.top(); + const auto nowchar = [&status]()->char{return map[status.now.x][status.now.y];}; + q.pop(); + + if(nowchar()=='a'){ + ans = std::min(ans,status.step); + return; + } + 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++; + const Status next_status {next,status.step+cost}; + vis[next_status.now.x][next_status.now.y] = true; + q.push(next_status); + } + } + return; +} + +int main(){ + is>>n; + for(ll _{0};_>h>>w; + for(ll i{1};i<=h;i++){ + for(ll j{1};j<=w;j++){ + is>>map[i][j]; + if(map[i][j]=='r')me.x=i,me.y=j; + } + } + bfs(me); + os<