您的位置:首页 > 其它

poj 1573 Robot Motion

2010-07-17 15:45 316 查看
http://acm.pku.edu.cn/JudgeOnline/problem?id=1573

一个简单的模拟题,

写这篇解题报告用于告诫英语跟我一样烂的兄弟姐妹们,

"whether or not the number before it is 1"意为:

无论前面的数字是否为1,step后面都要跟(s), 也就是无论前面的数字是什么, 都是step(s)

为此, 鄙人光荣的贡献了2个WA,囧

也怪自己没仔细去看题目, 想当然的以为当步数小于1时, 应该写成step....

ps: 被难题虐是应该的, 被水题虐得死去活来的是在不应该啊...- -

#include<iostream>
using namespace std;
int main()
{
int row, col, t, i, j, step[10][10], tmp, st, loopst;
char c[10][11];
bool visted[10][10], isLoop, isExit;
while(scanf("%d%d%d", &row, &col, &t) && (row||col||t))
{
memset(visted, 0, sizeof(visted));
for(i=0; i<row; i++)
scanf("%s", c[i]);
i = 0, j = t-1;
visted[i][j] = 1;
step[i][j] = 0;
isLoop = isExit = false;
st = 0;
while(1)
{
st++;
tmp = step[i][j];
switch(c[i][j])
{
case 'S':
i++; break;
case 'N':
i--; break;
case 'E':
j++; break;
case 'W':
j--; break;
default:
break;
}
if(i<0 || i>=row || j<0 || j>=col)
{
isExit = true;
break;
}
else if(visted[i][j])
{
isLoop = true;
st = step[i][j];
loopst = tmp - step[i][j] + 1;
break;
}
step[i][j] = tmp+1;
visted[i][j] = 1;
}
if(isExit)
printf("%d step(s) to exit/n", st);
else if(isLoop)
printf("%d step(s) before a loop of %d step(s)/n", st, loopst);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: