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:WA了,谁帮忙看看In Reply To:WA了,谁帮忙看看 Posted by:hudedi at 2006-03-11 13:49:06 > /*2157*/ > #include<stdio.h> > #define N 25 > > /*第一次找钥匙,用的是find标记,第二次找G,用的是 find2 标记*/ > /*一旦找到G,就将1赋给P*/ > > char maze[N][N]; > int find[N][N],key[8],p,find2[N][N]; > int m,n; > > void init() > { > int ii,jj; > p=0; > for(ii=0;ii<7;ii++) > key[ii]=0; > > for(ii=0;ii<m;ii++) > for(jj=0;jj<n;jj++) > find[ii][jj]=find2[ii][jj]=0; > > for(ii=0;ii<m;ii++) > scanf("%s",maze[ii]); > } > > int judge(int ii,int jj) > { > if(ii<m&&ii>=0&&jj<n&&jj>=0) > return 1; > else return 0; > } > > int need(int ii,int jj) > { > if((judge(ii,jj))&&!find[ii][jj]&&maze[ii][jj]!='X' > &&maze[ii][jj]!='A'&&maze[ii][jj]!='B'&&maze[ii][jj]!='C' > &&maze[ii][jj]!='D'&&maze[ii][jj]!='E'&&maze[ii][jj]!='G') > return 1; > else return 0; > } > > void bfs(int ii,int jj) > { > switch(maze[ii][jj]) > { > case 'a':key[1]++;break; > case 'b':key[2]++;break; > case 'c':key[3]++;break; > case 'd':key[4]++;break; > case 'e':key[5]++;break; > } > /*printf("%d %d\n",ii,jj); */ > find[ii][jj]=1; > if(need(ii-1,jj)) > bfs(ii-1,jj); > if(need(ii,jj-1)) > bfs(ii,jj-1); > if(need(ii+1,jj)) > bfs(ii+1,jj); > if(need(ii,jj+1)) > bfs(ii,jj+1); > } > > int out(char c) > { > int q=1; > switch(c) > { > case 'A':if(key[1]<3) > q=0; > break; > case 'B':if(key[2]<3) > { q=0;}break; > case 'C':if(key[3]<3) > { q=0;}break; > case 'D':if(key[4]<3) > { q=0;}break; > case 'E':if(key[5]<3) > { q=0;}break; > case 'X':q=0;break; > > } > if(q) > return 1; > else return 0; > } > > void open(int ii,int jj) > { > if(maze[ii][jj]=='G') > p=1; > find2[ii][jj]=1; > if(judge(ii-1,jj)&&out(maze[ii-1][jj])&&!find2[ii-1][jj]) > { > open(ii-1,jj); > } > if(judge(ii+1,jj)&&out(maze[ii+1][jj])&&!find2[ii+1][jj]) > { > open(ii+1,jj); > } > if(judge(ii,jj+1)&&out(maze[ii][jj+1])&&!find2[ii][jj+1]) > { > open(ii,jj+1); > } > if(judge(ii,jj-1)&&out(maze[ii][jj-1]) > &&!find2[ii][jj-1]) > { > open(ii,jj-1); > } > } > > int main() > { > int ii,jj; > while(scanf("%d%d",&m,&n)&&m) > { > init(); > > for(ii=0;ii<m;ii++) > for(jj=0;jj<n;jj++) > if(maze[ii][jj]=='S') > { > bfs(ii,jj); > /**/open(ii,jj); > goto inx; > } > > inx: > /* for(ii=0;ii<6;ii++) > printf("%d \n",key[ii]);*/ > if(p) > printf("YES\n"); > else > printf("NO\n"); > > } > return 1; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator