又是被自己的方向搞混了

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

#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. VS2008远程调试方法

    在网上找了好多资料才把这个调试环境搭好,下面总结一下: 先说明两个概念: 1.      目标机:远程需要调试的机子,也就是被调试程序exe所在的机子,该机子可以安装VS2008或者不安装vs2008 ...

  2. JS闭包的概念

    原文地址:http://zhidao.baidu.com/link?url=f81iaijX6nzY99Wz43v-p_qZEn4cCaomT4LD6NH5jVtI0yK2V76VJWefih51vA ...

  3. navigationBar 背景色

    if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 7.0) { [[UINavigationBar appearance] s ...

  4. Servlet页面间对象传递的方法

    Servlet页面间对象传递的方法 1.request 2.session 3.application 4.cookie 5.其它的

  5. [Redux] Generating Containers with connect() from React Redux (FooterLink)

    Code to be refactored: class FilterLink extends Component { componentDidMount() { const { store } = ...

  6. Base64编码和解码算法

    Base64么新鲜的算法了.只是假设你没从事过页面开发(或者说动态页面开发.尤其是邮箱服务),你都不怎么了解过,仅仅是听起来非常熟悉. 对于黑客来说,Base64与MD5算法有着相同的位置.由于电子邮 ...

  7. mobile web retina 下 1px 边框解决方案

    本文实际上想说的是ios8下 1px解决方案. 1px的边框在devicePixelRatio = 2的retina屏下会显示成2px,在iphone 6 plug 下,更显示成3px.由其影响美感. ...

  8. 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe

    题目没什么 只是线段相交稍微写的好看了点 Pipe Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  9. Android多媒体开发-stagefright及AwesomePlayer相关知识梳理

    android的多媒体框架中, stagefright其实是AwesomePlayer的代理,就是个皮包公司. status_t StagefrightPlayer::setDataSource( c ...

  10. Html5 Css实现方形图片 圆形显示

    <!doctype html><html><head><meta charset="utf-8"><title>方形图片 ...