POJ1573
来源:互联网 发布:怎么安装cad2008软件 编辑:程序博客网 时间:2024/05/22 15:20
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char gra[12][12];
int nowx, nowy;
int loop,count;
int r, c, pos;
bool flag = false;
bool check(int x, int y)
{
if(x >= 1 && x <= r && y >= 1 && y<= c)
{
if(gra[x][y] > 57)
return true;
else
{
flag = true;
loop = gra[x][y]-'0';
}
}
return false;
}
void fun(char a)
{
gra[nowx][nowy] = count +'0';
switch (a)
{
case 'W':
{
nowy--;
break;
}
case 'N':
{
nowx--;
break;
}
case 'E':
{
nowy++;
break;
}
case 'S':
{
nowx++;
break;
}
}
//cout<<"x"<<nowx<<"y"<<nowy<<endl;
}
int main()
{
int i, j;
char s;
while(scanf("%d %d %d",&r, &c, &pos), r && c && pos)
{
loop = 0;
count = 0;
flag = false;
for(i = 1; i <= r; i++ )
for( j = 1; j <= c ; j++)
cin>>gra[i][j];
nowx = 1;
nowy = pos;
while(check(nowx,nowy))
{
fun(gra[nowx][nowy]);
count++;
}
if(flag)
cout<<loop<<" step(s) before a loop of "<<count-loop<<" step(s)"<<endl;
else
cout<<count<<" step(s) to exit"<<endl;
}
}
#include <stdio.h>
#include <string.h>
using namespace std;
char gra[12][12];
int nowx, nowy;
int loop,count;
int r, c, pos;
bool flag = false;
bool check(int x, int y)
{
if(x >= 1 && x <= r && y >= 1 && y<= c)
{
if(gra[x][y] > 57)
return true;
else
{
flag = true;
loop = gra[x][y]-'0';
}
}
return false;
}
void fun(char a)
{
gra[nowx][nowy] = count +'0';
switch (a)
{
case 'W':
{
nowy--;
break;
}
case 'N':
{
nowx--;
break;
}
case 'E':
{
nowy++;
break;
}
case 'S':
{
nowx++;
break;
}
}
//cout<<"x"<<nowx<<"y"<<nowy<<endl;
}
int main()
{
int i, j;
char s;
while(scanf("%d %d %d",&r, &c, &pos), r && c && pos)
{
loop = 0;
count = 0;
flag = false;
for(i = 1; i <= r; i++ )
for( j = 1; j <= c ; j++)
cin>>gra[i][j];
nowx = 1;
nowy = pos;
while(check(nowx,nowy))
{
fun(gra[nowx][nowy]);
count++;
}
if(flag)
cout<<loop<<" step(s) before a loop of "<<count-loop<<" step(s)"<<endl;
else
cout<<count<<" step(s) to exit"<<endl;
}
}
0 0
- poj1573
- POJ1573
- POJ1573
- poj1573
- poj1573
- POJ1573
- POJ1573
- poj1573
- poj1573
- poj1573
- poj1573
- poj1573
- poj1573
- 纠结的poj1573.。。
- poj1573解题报告
- poj1573(简单的dfs)
- poj1573(模拟bfs)
- POJ1573--模拟--Robot Motion
- android启动过程再研
- 华为闯关-书签检索
- ebs 11i数据库job不能正常执行
- 给商学院经济学1203、1204、1205、1206班的一封信
- cocos2d-x 粒子特效
- POJ1573
- WebKit之loader模块理解学习
- LocalLR
- printf及无符号型整数
- 程序设计竞赛ACM训练手册 从入门到精通
- UVALive 6467 Strahler Order 拓扑排序
- HDU 1856 More is better
- 学习javacv之四:输入视频,简单处理后输出
- hdu1201 18岁生日