HDU1035 Robot Motion
来源:互联网 发布:软件项目保密措施 编辑:程序博客网 时间:2024/06/07 18:52
给定行、列、从第几列开始,让求出步数。
这道题用模拟就可以了,不需要用深搜,因为路线是唯一的。
记得初始化就好。
#include <cstdio>using namespace std;struct Node{ char a; int flag; int step;};int main(){ int row,col,start; Node Grid[15][15]; while((scanf("%d%d",&row,&col)) && row) { int i,j; scanf("%d",&start); for(i = 1; i <=row; i++) //初始化 { getchar(); for(j = 1; j <= col; j++) { scanf("%c",&Grid[i][j].a); Grid[i][j].flag = 0; Grid[i][j].step = 0; } } int Step = 0; int r,c; r = 1,c = start; while(1) { if(r==0||r>row||c==0||c>col) { printf("%d step(s) to exit\n",Step); break; } if(Grid[r][c].flag==1) { printf("%d step(s) before a loop of %d step(s)\n",Grid[r][c].step,Step-Grid[r][c].step); break; } Grid[r][c].flag = 1; Grid[r][c].step = Step; if(Grid[r][c].a=='N') { r--; } else if(Grid[r][c].a=='S') { r++; } else if(Grid[r][c].a=='W') { c--; } else if(Grid[r][c].a=='E') { c++; } Step++; } } return 0;}
阅读全文
0 0
- hdu1035 Robot Motion 模拟
- HDU1035:Robot Motion
- HDU1035 Robot Motion
- hdu1035.Robot Motion
- HDU1035 Robot Motion
- hdu1035 Robot Motion (DFS)
- HDU1035 Robot Motion(java)
- HDU1035 Robot Motion
- HDU1035 Robot Motion
- HDU1035 - Robot Motion (模拟)
- HDU1035 Robot Motion(BFS)
- HDU1035 Robot Motion(模拟)
- poj1573&&hdu1035 Robot Motion(模拟)
- HDU1035 Robot Motion【链式前向星】
- 杭电ACM—HDU1035 Robot Motion
- ACM-搜索之Robot Motion——hdu1035
- Robot Motion
- Robot Motion
- SSL P2690 fbi序列
- android Studio导入source文件
- spring浅解
- linux用ntpdate同步时间
- Problem F: 乌鸦坐飞机
- HDU1035 Robot Motion
- 子元素的margin-top 传递给了父元素
- TCP建链和拆链 数据交互 流量控制
- 无法远程访问Mysql的解决方案
- 搭建代理
- 上海python开发火的原因?
- 【Spring】Spring MVC原理及配置详解
- js原生table定义checkbox,并获取值放到数组
- java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed