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 |
这也有错,晕啊!#include<iostream> using namespace std; char a[23][23]; int large=0; void DFS(int i,int j,int counter,bool c[],bool visit[][23]) { if(!c[a[i][j]-'A'+1]) c[a[i][j]-'A'+1]=true; if(counter>large) large=counter; if(counter>large) large=counter; if(!visit[i+1][j] && !c[a[i+1][j]-'A'+1] && a[i+1][j]>='A' && a[i+1][j]<='Z') DFS(i+1,j,counter+1,c,visit); if(!visit[i-1][j] && !c[a[i-1][j]-'A'+1] && a[i-1][j]>='A' && a[i-1][j]<='Z') DFS(i-1,j,counter+1,c,visit); if(!visit[i][j+1] && !c[a[i][j+1]-'A'+1] && a[i][j+1]>='A' && a[i][j+1]<='Z') DFS(i,j+1,counter+1,c,visit); if(!visit[i][j-1] && !c[a[i][j-1]-'A'+1] && a[i][j-1]>='A' && a[i][j-1]<='Z') DFS(i,j-1,counter+1,c,visit); return; } int main() { int r,s; bool visit[23][23]; bool c[27]; memset(c,false,sizeof(c)); scanf("%d %d",&r,&s); while(getchar()!='\n'); for(int i=0;i<=21;i++) for(int j=0;j<=21;j++) { a[i][j]=0; visit[i][j]=true; }//init for(int i=1;i<=r;i++) { for(int j=1;j<=s;j++) { scanf("%c",&a[i][j]); visit[i][j]=false; } while(getchar()!='\n'); } DFS(1,1,1,c,visit); printf("%d\n",large); system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator