【模拟】HDU1035Robot Motion
来源:互联网 发布:苹果5刷机软件 编辑:程序博客网 时间:2024/06/07 13:45
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035
#include<bits/stdc++.h>using namespace std;const int N=1005;string s[N];//整行读入;int vis[N][N];//标记该位置是否走过,且记录是第几步走过int n,m,k;int check(int x,int y){if(x>n-1||y>m-1||x<0||y<0)return 1;if(vis[x][y])return 2;return 0;}int changeXY(int *x,int *y,char dir){if(dir=='E'){(*y)++;}else if(dir=='W'){(*y)--;}else if(dir=='N'){(*x)--;}else if(dir=='S'){(*x)++;}}void dfs(int x,int y){int ans;int step=1;//cout<<x<<' '<<y<<endl;vis[x][y]=step++;changeXY(&x,&y,s[x][y]);//cout<<x<<' '<<y<<endl;while(!(ans=check(x,y))){//cout<<x<<' '<<y<<endl;char dir=s[x][y];vis[x][y]=step++;changeXY(&x,&y,dir);}//cout<<ans<<endl;//cout<<x<<' '<<y<<endl;if(ans==1)cout<<step-1<<" step(s) to exit"<<endl;else cout<<vis[x][y]-1<<" step(s) before a loop of "<<step-vis[x][y]<<" step(s)"<<endl;}int main(){while(cin>>n>>m&&n&&m){memset(vis,0,sizeof(vis));cin>>k;for(int i=0;i<n;i++)cin>>s[i];dfs(0,k-1);}return 0;}
阅读全文
0 0
- HDU1035Robot Motion(模拟&&深搜)
- 【模拟】HDU1035Robot Motion
- hdu1035Robot Motion
- hdu1035 Robot Motion 模拟
- POJ1573--模拟--Robot Motion
- Robot Motion (模拟题)
- poj1573 Robot Motion (模拟)
- HDOJ1035 Robot Motion 【模拟】
- POJ1573 Robot Motion(模拟)
- Robot Motion(模拟法)
- poj1573 Robot Motion 模拟
- 模拟重力Parabolic Motion
- POJ 1573 Robot Motion模拟
- POJ 1573 Robot Motion 模拟
- POJ1573《Robot Motion》方法:模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573 Robot Motion 模拟
- poj Robot Motion(模拟)
- ffmpeg八大模块及常用函数介绍
- linux下的静态库和动态库
- Cache for MIPS
- Springmvc返回json数据
- 正则表达式全部符号解释
- 【模拟】HDU1035Robot Motion
- 利用FFmpeg玩转Android视频录制与压缩
- python2.x 和 python3.x的区别汇总
- vector的使用
- 教你如何查看Ubuntu版本
- C语言软件版本号宏定义的高级技巧
- 支持度与置信度
- Android studio 无法创建java类的解决办法
- JAVA实现卷帘式菜单