又是被自己的方向搞混了

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

#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. eclipse下使用hibernate tools实现hibernate逆向工程

    一  安装hibernate tools插件 1 在线安装 通过Eclipse的Help->Install New Software 在线安装插件,插件连接为: eclipse helios(3 ...

  2. UESTC_秋实大哥与家 2015 UESTC Training for Data Structures<Problem E>

    E - 秋实大哥与家 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  3. N-Queens 解答

    Question The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no tw ...

  4. pktgen使用详细教程

    网上有很多讲解pktgen的文章,但总是不够全面细致,看完之后自己还是不会写pktgen测试脚本,为此本文对pktgen进行详细的阐述,让大家看完本文后能够自己动手写pktgen shell. 1.p ...

  5. Python基础教程学习(四)类的创建与继承

    类中可以有方法,类外也可以有函数,其实类就是一种封装, Python中可以自己定义一个函数,一可以把这个函数在类中封装成一个方法, 其中的属性和方法自然就从父类中继承来了, 要想获得多个类的属性和功能 ...

  6. nginx的配置与安装

    说说在Linux系统下安装配置Nginx的详细过程. 1. 从Nginx官网下载Nginx.目前最新的稳定版为:1.6.2. 2. 将下载下来的Nginx上传到/opt/nginx目录下.运行“tar ...

  7. UIView 弹出动画

    // 展开动画 - (void)beginAnimations { CGContextRef context = UIGraphicsGetCurrentContext(); [UIView begi ...

  8. Winpcap网络编程九之Winpcap实战,ARP协议获得MAC表及主机通信

    大家好,本次我们须要完毕的任务是: 完毕两台主机之间的数据通信(数据链路层) 仿真ARP协议获得网段内主机的MAC表 使用帧完毕两台主机的通信(Hello! I'm -) 声明:本文章的目的是为大家的 ...

  9. apache 限制指定user_agent

    有些user_agent 不是我们想要的,可以通过rewrite功能针对 %{HTTP_USER_AGENT} 来rewirete到404页,从而达到限制某些user_agent的请求.   配置如下 ...

  10. C#中打日志导出日志到txt文本

    /// <summary> /// 打日志 /// </summary> /// <param name="log"></param> ...