poj 1573 Robot Motion_模拟
2013-07-24 22:01
295 查看
又是被自己的方向搞混了
题意:走出去和遇到之前走过的就输出。
题意:走出去和遇到之前走过的就输出。
#include <cstdlib> #include <iostream> #include<cstdio> using namespace std; #define N 110 int map ,visit ,n,m,flag;//n为x轴 m为y轴 int dir[][2]={{0,1},{1,0},{0,-1},{-1,0}};//e,s,w,n int setdire(char s){ switch(s){ case 'E':return 0; case 'S':return 1; case 'W':return 2; case 'N':return 3; } } void dfs(int x,int y,int num){ int i,j,tx,ty; if(flag!=1) return; tx=x+dir[map[x][y]][0]; ty=y+dir[map[x][y]][1]; if(tx>=0&&tx<n&&ty>=0&&ty<m){ if(visit[tx][ty]){ printf("%d step(s) before a loop of %d step(s)\n",visit[tx][ty]-1,num-visit[tx][ty]+1); flag=0; } else{ visit[x][y]=num; dfs(tx,ty,num+1); } } else{ printf("%d step(s) to exit\n",num); flag=0; } } int main(int argc, char *argv[]) { int i,j,x; char str ; while(scanf("%d%d%d",&n,&m,&x)&&(n||m||x)){ for(i=0;i<n;i++){ scanf("%s",str); for(j=0;j<m;j++){ map[i][j]=setdire(str[j]); } } memset(visit,0,sizeof(visit)); flag=1; dfs(0,x-1,1); } system("PAUSE"); return EXIT_SUCCESS; }
相关文章推荐
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- poj_1573 Robot Motion(简单模拟)
- POJ 1573-Robot Motion(模拟)
- poj 1573 Robot Motion 暑假训练第9题 模拟 大水题
- POJ 1573 && hdu 1035 Robot Motion(简单模拟)
- POJ 1573 Robot Motion(模拟)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- POJ-1573 Robot Motion 模拟水题
- HDU 1035 && poj 1573 Robot Motion【模拟】
- POJ 1573 Robot Motion (模拟+不回溯的dfs 水题)
- POJ 1573 Robot Motion 模拟
- POJ 1573 Robot Motion 模拟机器人行走
- POJ 1573 Robot Motion 模拟
- 模拟 POJ 1573 Robot Motion
- poj 1573 Robot Motion 模拟
- poj 1573 Robot Motion(java 模拟)
- poj 1573 Robot Motion 【模拟】【刷题计划】
- poj 1573 Robot Motion_模拟
- POJ 1573 Robot Motion(模拟)
- POJ 1573 Robot Motion 模拟