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> using namespace std; int W,H; char ch[22][22]; int tag[21][21]; int count=0; void TraceBack(int x,int y) { if(y-1>0 && tag[y-1][x]==0) { tag[y-1][x]=1; count++; TraceBack(x,y-1); } if(x+1<=W && tag[y][x+1]==0) { tag[y][x+1]=1; count++; TraceBack(x+1,y); } if(y+1<=H && tag[y+1][x]==0) { tag[y+1][x]=1; count++; TraceBack(x,y+1); } if(x-1>0 && tag[y][x-1]==0) { tag[y][x-1]=1; count++; TraceBack(x-1,y); } } int main() { while(cin>>W>>H && W) { count=0; int i,j; int x,y; for(i=1;i<=H;i++) for(j=1;j<=W;j++) { cin>>ch[i][j]; if(ch[i][j]=='.') tag[i][j]=0; else if(ch[i][j]=='#') tag[i][j]=1; if(ch[i][j]=='@') { tag[i][j]=0; x=j; y=i; } } TraceBack(x,y); cout<<count<<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