hdoj 1035 Robot Motion(简单题)
来源:互联网 发布:java 数组转字符串 编辑:程序博客网 时间:2024/05/21 07:50
我在输入字符二维数组的地方卡了一下
以后得习惯只用一个循环将每行看成一个字符串输入。而且最好不用scanf("\n"),容易卡住!
求从哪一步开始绕圈圈,设了b[11][11],每经过一个点(x,y)就将当前step赋给b[x][y]。b[x][y]也起到判断该点是否被访问过的作用。
#include<stdio.h>using namespace std;int main(){char a[11][11];int b[11][11];int r,c,s,i,j;int x,y,step;while(~scanf("%d%d%d",&r,&c,&s)&&r!=0){ step=0; x=0;y=s-1; for(i=0;i<r;i++) for(j=0;j<c;j++) b[i][j]=0; for(i=0;i<r;i++) scanf("%s",a[i]); while(1) { step++; if(a[x][y]=='N') { b[x][y]=step; x=x-1; } else if(a[x][y]=='S') { b[x][y]=step; x=x+1; } else if(a[x][y]=='E') {b[x][y]=step; y=y+1; } else {b[x][y]=step; y--; } if(x<0||x>=r||y<0||y>=c) { printf("%d step(s) to exit\n",step);break; } if(b[x][y]!=0) { printf("%d step(s) before a loop of %d step(s)\n",b[x][y]-1,step-b[x][y]+1); break; } } }return 0;}
阅读全文
0 0
- hdoj 1035 Robot Motion(简单题)
- hdoj 1035 Robot Motion
- HDOJ Robot Motion 1035
- Hdoj 1035 Robot Motion
- hdoj-1035Robot Motion
- HDOJ 1035 Robot Motion
- HDOJ 题目1035 Robot Motion(模拟)
- hdoj 1035 Robot Motion 【DFS】
- HDOJ HDU 1035 Robot Motion
- 1573 Robot Motion (简单题)
- hdoj 1035 Robot Motion (DFS+模拟)
- hdoj 1035 Robot Motion 【DFS 暴力】
- HDOJ(HDU).1035 Robot Motion (DFS)
- HDU ACM 1035 Robot Motion 简单模拟题
- HDU 1035 Robot Motion 简单模拟(挺有趣的一题)
- 【简单题】-POJ-1573-Robot Motion
- poj_1573 Robot Motion(简单模拟)
- hdu 1035 Robot Motion (DP)
- Java集合工具类Collections常用方法
- linux(六)其他常用命令
- Unable to validate using XSD: Your JAXP provider []
- Fraction to Recurring Decimal
- HDU0J #1717 小数化分数
- hdoj 1035 Robot Motion(简单题)
- NOI题解(1.10编程基础之简单排序)
- C/C++内存泄漏及检测
- (156)定制UV
- c++ string比较大小
- tomcat报错:The Tomcat server configuration at \Servers\Tomcat v7.0 Server at localhost-config is missi
- C++求解:平面上有n个点,问总共可以组成多少条直线
- [DP]343. Integer Break
- 2017中国大学生程序设计竞赛