HDU-1035 Robot Motion 模拟问题(水题)
2018-02-06 21:13
573 查看
题目链接:https://cn.vjudge.net/problem/HDU-1035
水题
代码
#include <cstdio> #include <map> int height, width, sp, dir[4][2]={1, 0, 0, -1, -1, 0, 0, 1}; std::map<char, int> todir; char map[15][15]; int solve(int x, int y, int step, int vis[][15], int &loop){ if (x<0 || y<0 || x>=width || y>=height) {loop=0; return step;} if (vis[y][x]) {loop=step-vis[y][x]; return step-loop;} vis[y][x]=step; return solve(x+dir[todir[map[y][x]]][0], y+dir[todir[map[y][x]]][1], step+1, vis, loop); } int main(void){ todir['E']=0; todir['N']=1; todir['W']=2; todir['S']=3; while (scanf("%d%d", &height, &width)==2 && height){ scanf("%d", &sp); for (int y=0; y<height; y++) scanf("%s", map[y]); int vis[15][15]={0}, loop, cnt=solve(sp-1, 0, 1, vis, loop); if (!loop) printf("%d step(s) to exit\n", cnt-1); else printf("%d step(s) before a loop of %d step(s)\n", cnt-1, loop); } return 0; }
相关文章推荐
- hdu1035 Robot Motion 模拟
- POJ 1573 && hdu 1035 Robot Motion(简单模拟)
- HDU-1034 Candy Sharing Game 模拟问题(水题)
- poj1573&&hdu1035 Robot Motion(模拟)
- hdu 1035 Robot Motion(模拟)
- HDU 1035--Robot Motion(模拟)
- 【POJ】1573 & 【HDU】1035 - Robot Motion(模拟)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- HDU-1225 Football Score 模拟问题(水题)
- HDU 1035 && poj 1573 Robot Motion【模拟】
- HDU 1035 Robot Motion 模拟
- HDU 1035 Robot Motion(大模拟)
- HDU1035 - Robot Motion (模拟)
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
- HDU 1035 Robot Motion 简单模拟(挺有趣的一题)
- poj1573&&hdu1035 Robot Motion(模拟)
- HDU-1035-Robot Motion(开两个数组简单模拟,话说最近一直再做模拟......C++)
- hdu 1035 Robot Motion(模拟)
- HDU 1035 Robot Motion(简单题,模拟)
- HDU 1035 Robot Motion (模拟)