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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDU2102 A计划

發布時間:2025/3/21 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU2102 A计划 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

解題思路:一道簡單題,卻WA了十幾發,犯幾個低級錯誤。還是不能急躁,

    ? ? 內心要平靜,具體分析見代碼:

1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 const int maxn = 15; 8 char mapp[maxn][maxn][2]; 9 int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; 10 int n, m, t, c; 11 12 struct node{ 13 int x, y; 14 int f; 15 int step; 16 }s, e; 17 18 queue<node> q; 19 20 int bfs() 21 { 22 while(!q.empty()) q.pop(); //沒加這步WA了好多發 23 q.push(s); 24 25 while(!q.empty()) 26 { 27 s = q.front(); q.pop(); 28 //debug時可打印路徑 29 //printf("s.x = %d, s.y = %d, s.step = %d, s.flag = %d\n", s.x, s.y, s.step, s.flag); 30 31 32 for(int i = 0; i < 4; i++) 33 { 34 e.x = s.x + dir[i][0]; 35 e.y = s.y + dir[i][1]; 36 e.step = s.step + 1; 37 e.f = s.f; 38 39 if(e.step > t || mapp[e.x][e.y][e.f] == '*') continue;//超過時間或不能走 40 if(mapp[e.x][e.y][e.f] == '#') 41 { 42 mapp[e.x][e.y][e.f] = '*'; //標記為已走過 43 e.f = 1 - e.f; //穿越到另一層 44 //另一層若為#或*則標記為不能走 45 if(mapp[e.x][e.y][e.f] == '#' || mapp[e.x][e.y][e.f] == '*') 46 { 47 mapp[e.x][e.y][e.f] = '*'; 48 continue; //必不可少 49 } 50 } 51 52 if(mapp[e.x][e.y][e.f] == 'P') return 1; //找到公主 53 mapp[e.x][e.y][e.f] = '*'; //標記為已走過 54 q.push(e); 55 } 56 } 57 return 0; //規定時間沒找到 58 } 59 60 int main() 61 { 62 scanf("%d", &c); 63 while(c --) 64 { 65 memset(mapp, '*', sizeof(mapp)); 66 scanf("%d %d %d", &n, &m, &t); 67 68 for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) 69 scanf(" %c", &mapp[i][j][0]); 70 71 for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) 72 scanf(" %c", &mapp[i][j][1]); 73 74 s.x = 1, s.y = 1, s.step = 0, s.f = 0; 75 if(bfs()) printf("YES\n"); 76 else printf("NO\n"); 77 } 78 return 0; 79 } View Code

?

轉載于:https://www.cnblogs.com/loveprincess/p/4887264.html

總結

以上是生活随笔為你收集整理的HDU2102 A计划的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。