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 |
一直RE,求大神看看#include<iostream> #include<cstdio> #include<cstring> using namespace std; char a[100][100]; bool v[100][100]; int m,n,ll,lr,mi; int zuo(int x,int y,int z) { ll++; if(a[x][y]=='E')return 0; if(z==1) { if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))zuo(x,y-1,4); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))zuo(x-1,y,1); else if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))zuo(x,y+1,2); else if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))zuo(x+1,y,3); } else if(z==2) { if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))zuo(x-1,y,1); else if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))zuo(x,y+1,2); else if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))zuo(x+1,y,3); else if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))zuo(x,y-1,4); } else if(z==3) { if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))zuo(x,y+1,2); else if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))zuo(x+1,y,3); else if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))zuo(x,y-1,4); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))zuo(x-1,y,1); } else if(z==4) { if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))zuo(x+1,y,3); else if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))zuo(x,y-1,4); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))zuo(x-1,y,1); else if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))zuo(x,y+1,2); } return 0; } int you(int x,int y,int z) { lr++; if(a[x][y]=='E')return 0; if(z==1) { if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))you(x,y+1,2); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))you(x-1,y,1); else if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))you(x,y-1,4); else if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))you(x+1,y,3); } else if(z==2) { if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))you(x+1,y,3); else if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))you(x,y+1,2); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))you(x-1,y,1); else if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))you(x,y-1,4); } else if(z==3) { if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))you(x,y+1,2); else if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))you(x+1,y,3); else if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))you(x,y-1,4); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))you(x-1,y,1); } else if(z==4) { if(y-1>=0&&(a[x][y-1]=='.'||a[x][y-1]=='E'))you(x,y-1,4); else if(x+1<m&&(a[x+1][y]=='.'||a[x+1][y]=='E'))you(x+1,y,3); else if(y+1<n&&(a[x][y+1]=='.'||a[x][y+1]=='E'))you(x,y+1,2); else if(x-1>=0&&(a[x-1][y]=='.'||a[x-1][y]=='E'))you(x-1,y,1); } return 0; } int go(int x,int y,int z) { v[x][y]=1; if(a[x][y]=='E') { if(z<mi)mi=z; return 0; } if(x-1>=0&&a[x-1][y]!='#'&&v[x-1][y]==0) { go(x-1,y,z+1); v[x-1][y]=0; } if(x+1<m&&a[x+1][y]!='#'&&v[x+1][y]==0) { go(x+1,y,z+1); v[x-1][y]=0; } if(y-1>=0&&a[x][y-1]!='#'&&v[x][y-1]==0) { go(x,y-1,z+1); v[x][y-1]=0; } if(y+1<n&&a[x][y+1]!='#'&&v[x][y+1]==0) { go(x,y+1,z+1); v[x][y+1]=0; } return 0; } int main() { int t,sx,sy; scanf("%d",&t); while(t--) { int ji=0; memset(v,0,sizeof(v)); scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { scanf("%s",&a[i]); if(ji==0) { for(int j=0;j<n;j++) { if(a[i][j]=='S') { ji=1; sx=i; sy=j; } } } } ll=0; lr=0; zuo(sx,sy,1); you(sx,sy,1); mi=lr; go(sx,sy,1); cout<<ll<<" "<<lr<<" "<<mi<<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