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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ 1573 POJ 2632(两道有趣的Robot)实例

發布時間:2025/6/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1573 POJ 2632(两道有趣的Robot)实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/* ** POJ 2632 Crashing Robots ** Created by Rayn @@ 2014/04/16 ** 坑爹的模擬題,腦殼不清晰的就要被坑慘了 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std;const int MAX = 110;struct pos{int id, dir; /* N-0,E-1,S-2,W-3 */int x, y; };pos rob[MAX]; int HaveRob[MAX][MAX]; int K, A, B, N, M; int mov[4][2] = {{0, 1},{1, 0},{0, -1},{-1, 0}};int DirToNum(char ch) {switch(ch){case 'N':return 0;case 'E':return 1;case 'S':return 2;case 'W':return 3;default:break;}return -1; } int CrashWall(int x, int y) {if(x<=0 || x>A || y<=0 || y>B)return 1;return 0; } int main() {char str[10], act[10];int num, rep;scanf("%d", &K);while(K--){memset(HaveRob, 0, sizeof(HaveRob));scanf("%d%d%d%d", &A, &B, &N, &M);for(int i=1; i<=N; ++i){scanf("%d %d %s", &rob[i].x, &rob[i].y, str);rob[i].dir = DirToNum(str[0]);rob[i].id = i;HaveRob[rob[i].x][rob[i].y] = i;}int first = 1, ok = 1, tx, ty;while(M--){scanf("%d %s %d", &num, act, &rep);if(!first)continue;while(rep--){if(act[0] == 'L'){rob[num].dir = (rob[num].dir + 3) % 4;}if(act[0] == 'R'){rob[num].dir = (rob[num].dir + 1) % 4;}if(act[0] == 'F'){tx = rob[num].x + mov[rob[num].dir][0];ty = rob[num].y + mov[rob[num].dir][1];if(CrashWall(tx, ty) && first){printf("Robot %d crashes into the wall\n", num);first = ok = 0;}if(HaveRob[tx][ty] && first){printf("Robot %d crashes into robot %d\n", num, HaveRob[tx][ty]);first = ok = 0;}HaveRob[rob[num].x][rob[num].y] = 0;rob[num].x = tx;rob[num].y = ty;HaveRob[rob[num].x][rob[num].y] = num;}}}if(ok)printf("OK\n");}return 0; } /* ** POJ 2688 Cleaning Robot ** Created by Rayn @@ 2014/05/07 ** 好久沒做搜索,又寫錯了dir方向數組 ** 豎向是x坐標,橫向是y坐標 */ #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int MAX = 15;int dir[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};/* N,S,E,W */ int loop, step; int maze[MAX][MAX], vis[MAX][MAX];void Init() {memset(vis, 0, sizeof(vis));for(int i=0; i<MAX; ++i){for(int j=0; j<MAX; ++j){maze[i][j] = 5;?//在地圖外圈置為5,方便判斷出界}} } int Trans(char ch) {int dir = 5;switch(ch){case 'N':return 0;case 'S':return 1;case 'E':return 2;case 'W':return 3;default:break;}return dir; } void DFS(int x, int y, int s) {if(maze[x][y] == 5){step = s;loop = -1;return ;}if(vis[x][y] != 0){step = vis[x][y] - 1;loop = s - step;return ;}vis[x][y] = s + 1;int tx = x + dir[maze[x][y]][0];int ty = y + dir[maze[x][y]][1];DFS(tx, ty, vis[x][y]); } int main() { #ifdef _Raynfreopen("in.txt", "r",stdin); #endifint h, w, start;char tmp[15];while(scanf("%d%d%d", &h, &w, &start) != EOF){if(h==0 && w==0 && start==0)break;Init();for(int i=1; i<=h; ++i){scanf("%s", tmp);for(int j=0; j<w; ++j){maze[i][j+1] = Trans(tmp[j]);}}loop = 0;DFS(1, start, 0);if(loop == -1)printf("%d step(s) to exit\n", step);elseprintf("%d step(s) before a loop of %d step(s)\n", step, loop);}return 0; }

總結

以上是生活随笔為你收集整理的POJ 1573 POJ 2632(两道有趣的Robot)实例的全部內容,希望文章能夠幫你解決所遇到的問題。

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