日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nyoj-999 师傅又被妖怪抓走了

發(fā)布時間:2025/3/16 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nyoj-999 师傅又被妖怪抓走了 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

http://acm.nyist.net/JudgeOnline/problem.php?pid=999? ? ??

題解: ??把師傅所在行和列標記為 1 狀態(tài) ? 'd'

二師兄所在行和列標記為 2 狀態(tài) ? 'e'

如果師傅和二師兄在同一行或同一列,重合的部分標記為3狀態(tài) 'x'

要想把師傅和二師兄都找到:

要么先找到師傅,再找到二師兄;

? ? ?要么先找到二師兄,再找到師傅;

? ? ?要么同時找到

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<cmath> using namespace std; const int dx[] = {1,-1,0,0}; const int dy[] = {0,0,1,-1}; bool vis[105][105][5]; char map[105][105]; int n,m,t; struct node{int x,y;int step,st; }; bool ok(int x,int y){//判斷的是否能走,可以把師傅或二師兄看做墻即不能走if(map[x][y] == 'E'|| map[x][y] == 'D' || map[x][y] == 'X')return false;return true; } char graph(char c,int Bool){//師傅或二師兄所在的行和列標記有多不同if((Bool && c == 'e') || (!Bool && c == 'd'))return 'x';//'x'可以記為把師傅和二師兄都被找到的狀態(tài)return Bool?'d':'e'; } void solve(int x,int y,int Bool)//處理師傅或二師兄所在的行和列 {for(int i = x + 1;i < n && ok(i,y);i++)map[i][y] = graph(map[i][y],Bool);for(int i = x - 1;i >= 0 && ok(i,y);i--)map[i][y] = graph(map[i][y],Bool);for(int i = y + 1;i < m && ok(x,i);i++)map[x][i] = graph(map[x][i],Bool);for(int i = y - 1;i >= 0 && ok(x,i);i--)map[x][i] = graph(map[x][i],Bool); } int getST(char c,int st){//處理當前所走的狀態(tài)if(c == 'd') st |= 1;else if(c == 'e') st |= 2;else if(c == 'x') st |= 3;return st; } bool find(int x,int y,int st){if(!ok(x,y)) return false;if(vis[x][y][st]) return false;if(x < 0 || x > n || y < 0 || y > m) return false;return true; } int bfs(int sta,int end){memset(vis,false,sizeof(vis));node p,q;queue<node> Q;p.x = sta,p.y = end,p.step = 0;p.st = getST(map[sta][end],0);vis[p.x][p.y][p.st] = true;Q.push(p);while(!Q.empty()){q = Q.front();Q.pop();if(q.st == 3) return q.step;//問是否能達到3的狀態(tài),即師傅和二師兄都被找到for(int i = 0;i < 4;i++){p.x = dx[i] + q.x;p.y = dy[i] + q.y;p.st = q.st;if(find(p.x,p.y,p.st)){p.st = getST(map[p.x][p.y],p.st);p.step = q.step + 1;vis[p.x][p.y][p.st] = true;Q.push(p);}}}return 900; } int main(){int sx,sy,ca = 1;while(~scanf("%d%d%d",&n,&m,&t)){getchar();for(int i = 0;i < n;i++){cin >> map[i];for(int j = 0;j < m;j++)if(map[i][j] == 'S')sx = i,sy = j;}for(int i = 0;i < n;i++){for(int j = 0;j < m;j++){if(map[i][j] == 'D')solve(i,j,1);else if(map[i][j] == 'E')solve(i,j,0);}}printf("Case %d:\n",ca++);int ans = bfs(sx,sy);if(ans <= t)printf("%d\n",ans);else puts("-1");} }

總結(jié)

以上是生活随笔為你收集整理的nyoj-999 师傅又被妖怪抓走了的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。