POJ 1753 Robot Motion
来源:互联网 发布:角度尺软件 编辑:程序博客网 时间:2024/05/19 14:35
这是一道水题啊、、、纯模拟啊、、、但是还是敲了老长时间啊,各种不注意细节啊。。。sad啊、下次一定要改啊、、、、、、
题意很简单就每一步都是一个命令,如果能走出来就输出需要走的步数,否则输出走几步到环,在环里需要走几步。
#include <stdio.h>#include <string.h>int main(){ int n, m, i, j, t; int dp[110][110], dx[4]= {1, 0, -1, 0}, dy[4]= {0 , -1, 0, 1}; int map[110][110]; char s[110][110]; while(~scanf("%d %d %d",&n, &m, &t) && (n || m || t)) { memset(dp, 0 , sizeof(dp)); for(i = 0; i < n; i++) scanf("%s",s[i]); for(i = 0; i < n; i++) { for(j = 0; j < m; j++) { if(s[i][j] == 'S') map[i][j] = 0; else if(s[i][j] == 'W') map[i][j] = 1; else if(s[i][j] == 'N') map[i][j] = 2; else if(s[i][j] == 'E') map[i][j] = 3; } } int flat = 0; int x = 0, y = t-1; int cnt = 0, count = 0; int q; dp[x][y] = 1; q = x; x += dx[map[x][y]]; y += dy[map[q][y]]; cnt ++; while(1) { if(dp[x][y] == 0) { if(x<0 || x>=n || y<0 || y>=m) { printf("%d step(s) to exit\n", cnt); break; } else { dp[x][y] = 1; int p = x; x += dx[map[x][y]]; y += dy[map[p][y]]; cnt++; } } else { flat = 1; dp[x][y]++; break; } } if(flat == 1) { x = 0, y = t-1; while(1) { if(dp[x][y] != 2) { int p = x; x += dx[map[x][y]]; y += dy[map[p][y]]; count ++; } else if(dp[x][y] == 2) { printf("%d step(s) before a loop of %d step(s)\n",count, cnt-count); break; } } } } return 0;}
- POJ 1753 Robot Motion
- poj 1573 Robot Motion
- Poj 1573 Robot Motion
- poj 1573 Robot Motion
- POJ 1573 - Robot Motion
- poj-1573-Robot Motion
- POJ 1573 Robot Motion
- POJ 1573 Robot Motion
- POJ-1573-Robot Motion
- poj 1573 Robot Motion
- poj 1537 Robot Motion
- POJ 1573 Robot Motion
- POJ 1573 Robot Motion.
- poj 1573 Robot Motion
- POJ -1573 Robot Motion
- POJ 1573:Robot Motion
- poj 1573 Robot Motion
- poj 1573 Robot Motion
- linux配置java环境变量
- Eclipse代码编辑区,着色插件(Eclipse Color Theme)的安装
- iOS: NSDictionary的方法initWithObjectsAndKeys:
- 02. SQL表达式的灵活使用
- Linux常用小知识
- POJ 1753 Robot Motion
- python手记(22)
- PHP学习笔记
- 就是喜欢这张配图,没什么好解释的。。。
- iOS: NSDictionary的方法isEqualToDictionary:
- rose画用例图折线变直线
- iOS: NSDictionary的方法keyEnumerator
- ASP学习
- HDU 3008 Warcraft (DP 背包)