poj 1573

题意:给定每一步的定方向与初始位置  让求出去房间 或者进入循环的步数

直接模拟


#include<iostream>
#include<cstring>
using namespace std;
int map[11][11];
int v[11][11];
int dir[4][2]={-1,0,1,0,0,-1,0,1};
int main()
{
int m,n,y,x,step,i,j;
int xx,yy;
char c;
while(cin>>m>>n>>y)
{
if(m==n&&n==y&&y==0) break;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
cin>>c;
switch(c){
case ‘N‘:map[i][j]=0;break;
case ‘S‘:map[i][j]=1;break;
case ‘W‘:map[i][j]=2;break;
case ‘E‘:map[i][j]=3;break;
}
}
x=1;
step=0;
memset(v,-1,sizeof(v));
while(true)
{
xx=x;yy=y;
v[x][y]=step++;
x+=dir[map[xx][yy]][0];
y+=dir[map[xx][yy]][1];
if(x<=0||x>m||y<=0||y>n)
{
cout<<step<<" step(s) to exit"<<endl;
break;
}
if(v[x][y]!=-1)
{
cout<<v[x][y]<<" step(s) before a loop of "<<step-v[x][y]<<" step(s)"<<endl;
break;
}
}
}
return 0;
}

poj 1573,布布扣,bubuko.com

时间: 2024-10-17 03:09:28

poj 1573的相关文章

POJ 1573 Robot Motion(模拟)

题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14195   Accepted: 6827 Description A robot has been programmed to follow the instructions in its path. Instr

POJ 1573 &amp; POJ 2632(两道有趣的Robot)

题目链接:POJ 1573 Robot Motion & POJ 2632 Crashing Robots [题意]题意就不说了,有兴趣从链接点进去看吧,就是机器人各种打扫房间,行驶指令. [思路]2632是一道纯模拟题,只要把题意读懂,就可以用代码模拟过程,只是写起来有点蛋疼,代码力还是欠缺啊.而1573感觉挺新奇的,我用的DFS来模拟,好久没有写DFS,一开始又把dir数组写错了,结果总是得出0. 下面贴代码,先是2632的AC代码: 1 /* 2 ** POJ 2632 Crashing

POJ 1573:Robot Motion

Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10267   Accepted: 5001 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in

POJ 1573 Robot Motion【是搜索,就不要纠结是DFS还是BFS】

Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12845   Accepted: 6234 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in

69棋牌游戏源码,POJ 1573 Robot Motion模拟

主题:http://pj.org/Debug ID=1573    主要思想:棋盘上充满了N,E,S,W指令.人们按照棋盘的指示从北方的初始列开始移动,直到你下完棋或四处走动.    N意味着向北(向上)移动.    E意味着向东移动(右).    S意味着向南移动(下).    W意味着向西移动(左).    分析:因为棋盘只有10*10,也就是说最多只有100步,所以您可以使用模拟算法.我们声明一个用于记录指令的字符卡映射,以及一个初始值为零的象棋卡,用于记录所走过的路径.国际象棋棋局或发现

POJ 1573 Robot Motion 搜索

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6297    Accepted Submission(s): 2952 Problem Description A robot has been programmed to follow the instructions in its path. Instruc

poj 1573 Robot Motion

Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N north (up the page) S south (down the page) E east (to t

Robot Motion - poj 1573

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11269   Accepted: 5486 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The

POJ题目分类推荐 (很好很有层次感)

著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递