又是被自己的方向搞混了

题意:走出去和遇到之前走过的就输出。

#include <cstdlib>
#include <iostream>
#include<cstdio>
using namespace std;
#define N 110
int map[N][N],visit[N][N],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[N];
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 Robot Motion_模拟的更多相关文章

  1. POJ 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...

  2. 模拟 POJ 1573 Robot Motion

    题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...

  3. POJ 1573 Robot Motion(模拟)

    题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...

  4. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  5. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  6. POJ 1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12978   Accepted: 6290 Des ...

  7. UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作

    AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...

  8. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  9. POJ 1573:Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11324   Accepted: 5512 Des ...

随机推荐

  1. 你真的会玩SQL吗?透视转换

    原文:你真的会玩SQL吗?透视转换 透视转换是一种行列互转的技术,在转过程中可能执行聚合操作,应用非常广泛. 本章与 你真的会玩SQL吗?数据聚合 内容比较重要,还涉及到 你真的会玩SQL吗?Case ...

  2. 遇到的Fragment中使用setAdapter()设置ListView报空指针解决方案

    场景是这样,底部4个tab导航栏.用的fragment. 但其中一个fragmentActivity1中使用ListVIew的setAdapter()方法时,总是报NullPointerExcepti ...

  3. eclipse工具再学习

    今天下午最后近1小时及晚上2个多小时,我都花费时间在工程环境配置上,自尊心被严重摧残,各种郁闷和抱怨.源头是我部分刷新代码后运行工程依赖的jar报错,后来找同事发现是因为我没更新pom.xml文件,重 ...

  4. Median of Two Sorted Arrays 解答

    Question There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median o ...

  5. LeeCode-Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  6. Cuckoo hash算法分析

    一 基本思想: cuckoo hash是一种解决hash冲突的方法,其目的是使用简单的hash 函数来提高hash table的利用率,同时保证O(1)的查询时间 基本思想是使用2个hash函数来处理 ...

  7. Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏

    Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...

  8. JS~delegate与live

    在jquery里有两个方法可以用来绑定自动追加出来的DOM对象,它们是live和delegate,事实上,这两个方法是bind方法的一个变体,在对于固定DOM对象时,我们通常使用bind就可以了,而对 ...

  9. LFS: Interface eth0 doesn't exist

    环境 宿主主机:Ubuntu 14.04.4 LTS 32位 LFS内核:Linux 4.2.0 好不用容易将LFS引导起来了,但系统启动后,无法配置网口.系统启动时提示:Interface eth0 ...

  10. 【并查集专题】【HDU】

    PS:做到第四题才发现 2,3题的路径压缩等于没写 How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...