| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
麻烦问下 我这个程序在浙大上AC Mid Central Regionals上找的数据也对 请问是加数据了么?能给贴下么?谢谢#include<iostream>
using namespace std;
char a[11][11];
int s[11][11];
struct node{
int x,y;
};
int counter = 0;
node transform(node temp){
int x = temp.x,y = temp.y;
if(a[x][y]=='N') {
temp.x = x-1;
}
else if(a[x][y]=='W') {
temp.y = y-1;
}
else if(a[x][y]=='S') {
temp.x = x+1;
}
else {
temp.y = y+1;
}
s[x][y] = counter;
return temp;
}
int main(){
int m,n,begin;
while(cin>>n>>m>>begin&&n!=0&&m!=0&&begin!=0){
counter = 0;
memset(s,-1,sizeof(s));
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cin>>a[i][j];
}
}
node temp;
temp.x = 0;
temp.y = begin-1;
s[temp.x][temp.y] = 0;
while(1){
counter++;
temp = transform(temp);
if(temp.x<0||temp.x>=n||temp.y<0||temp.y>=m){
cout<<counter<<" step(s) to exit\n";
break;
}
if(s[temp.x][temp.y]>=0){
cout<<s[temp.x][temp.y]-1<<" step(s) before a loop of ";
int max = -1;
if(s[temp.x][temp.y-1]>=0&&s[temp.x][temp.y-1]>max){
max = s[temp.x][temp.y-1];
}
if(s[temp.x][temp.y+1]>=0&&s[temp.x][temp.y+1]>max){
max = s[temp.x][temp.y+1];
}
if(s[temp.x-1][temp.y]>=0&&s[temp.x-1][temp.y]>max){
max = s[temp.x-1][temp.y];
}
if(s[temp.x+1][temp.y]>=0&&s[temp.x+1][temp.y]>max){
max = s[temp.x+1][temp.y];
}
cout<<max-s[temp.x][temp.y]+1<<" step(s)\n";
break;
}
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator