| ||||||||||
| 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 | |||||||||
郁闷啊,边缘测试都能过,为什么还是WA啊,请大神们看看或者给提供个测试数据!#include <iostream>
#include <cstring>
using namespace std;
char grid[12][12];
int map[12][12];
void work(int &r,int &c)
{
if(grid[r][c]=='E') c++;
else if(grid[r][c]=='S') r++;
else if(grid[r][c]=='N') r--;
else c--;
}
int main()
{
memset(grid,0,sizeof(grid));
memset(map,0,sizeof(map));
int rows,columns,entry;
int i,j;
int r,c;
int steps;
int flag=0;
int st1,st2;
int tr,tc,ttc;
while(cin>>rows>>columns>>entry)
{
if(rows==0&&columns==0&&entry==0) break;
steps=0;
c=entry-1;
r=0;
tr=0;tc=entry-1;
ttc=entry-1;
for(i=0;i<rows;i++)
for(j=0;j<columns;j++)
cin>>grid[i][j];
while(r>=0&&c>=0)
{
work(r,c);
steps++;
if(steps>rows*columns)
{
steps=0;
st1=0;st2=0;
flag=1;
break;
}
}
if(flag){
while(map[tr][tc]==0)
{
st1++;
map[tr][tc]=1;
work(tr,tc);
if(map[tr][tc]==1) break;
}
int ttr=0;
while(ttr!=tr||ttc!=tc)
{
st2++;
work(ttr,ttc);
}
}
memset(grid,0,sizeof(grid));
memset(map,0,sizeof(map));
if(flag)
{
cout<<st2<<" step(s) before a loop of "<<(st1-st2)<<" step(s)"<<endl;
}
else
cout<<steps<<" step(s) to exit"<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator