POJ 1573 Robot Motion 模拟 难度:0
2015-08-24 11:50
351 查看
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> using namespace std; int A,B,sx,sy; char maz[101][101]; int vis[101][101]; const int dx[4]={0,1,0,-1}; const int dy[4]={-1,0,1,0}; int dir(char ch){ if(ch=='N')return 0; else if(ch=='E')return 1; else if(ch=='S')return 2; return 3; } void print(int step){ for(int s=1;s<step;s++){ for(int i=0;i<A;i++){ for(int j=0;j<B;j++){ if(vis[j][i]==s){ printf("vis[%d][%d]:%d\n",j,i,vis[j][i]); } } } } } void solve(){ memset(vis,0,sizeof(vis)); sx--;sy=0; int step=0; int fx,fy; while(!vis[sy][sx]&&sx>=0&&sx<A&&sy>=0&&sy<B&&++step){ fx=sx;fy=sy; vis[sy][sx]=step; sx=dx[dir(maz[fy][fx])]+fx; sy=dy[dir(maz[fy][fx])]+fy; } if(sx<0||sy<0||sx>=A||sy>=B)printf("%d step(s) to exit\n",step); else { printf("%d step(s) before a loop of %d step(s)\n",vis[sy][sx]-1,step+1-vis[sy][sx]); } } int main(){ #ifndef ONLINE_JUDGE freopen("output.txt","w",stdout); #endif // ONLINE_JUDGE while(scanf("%d%d%d",&B,&A,&sx)==3&&A&&B){ for(int i=0;i<B;i++)scanf("%s",maz[i]); solve(); } return 0; }
相关文章推荐
- contains选择器
- CKEditor+CKFinder
- 学好英语的七个规则(上)
- ExtJs combobox下拉框宽度设置
- 基于MVC4+EasyUI的Web开发框架经验总结(4)--使用图表控件Highcharts
- ie下onchange事件触发不到
- 算法题——立方体的体对角线穿过多少个正方体?
- mysql索引结构原理、性能分析与优化
- ghigli logo ploted by matlab
- 面向接口编程详解(二)——编程实例
- 八种常见排序算法:插入、冒泡、选择、希尔、归并、快排、堆排序、基数排序
- [教程二]用OD给游戏打补丁! [2010-06-11]
- 八种常见排序算法:插入、冒泡、选择、希尔、归并、快排、堆排序、基数排序
- binbinyang---通过XML 自定义 设置圆形BUTTON
- SegmentedControl
- 页面分享代码share
- POJ 2632 Crashing Robots 模拟 难度:0
- php 利用socket发送HTTP请求(GET,POST)
- jQuery仿360导航页图标拖动排序效果代码分享
- 编程风格(java)