标签:des style class blog c code
4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
NO YES
1 #include <stdio.h> 2 #include <stdlib.h> 3 int Len_X,Len_Y,D,SIGN; 4 int End_x,End_y; 5 char Map[100][100]; 6 int DFS(int x,int y,int d,int D) 7 { 8 if(SIGN==1)return 1; 9 if(x==End_x&&y==End_y&&d==D){SIGN+=1;return 1;} 10 if(Map[x][y]==‘X‘)return 0; 11 else Map[x][y]=‘X‘; 12 if(d>=D) {return 0;} 13 if(x+1<Len_X&&Map[x+1][y]!=‘X‘) 14 { 15 DFS(x+1,y,d+1,D); 16 Map[x+1][y]=‘.‘; 17 } 18 if(x-1>=0&&Map[x-1][y]!=‘X‘) 19 { 20 DFS(x-1,y,d+1,D); 21 Map[x-1][y]=‘.‘; 22 } 23 if(y+1<Len_Y&&Map[x][y+1]!=‘X‘) 24 { 25 DFS(x,y+1,d+1,D); 26 Map[x][y+1]=‘.‘; 27 } 28 if(y-1>=0&&Map[x][y-1]!=‘X‘) 29 { 30 DFS(x,y-1,d+1,D); 31 Map[x][y-1]=‘.‘; 32 } 33 return 0; 34 } 35 36 int main() 37 { 38 int Begin_x,Begin_y,i,j,flat,A,B; 39 while(scanf("%d%d%d",&Len_X,&Len_Y,&D)!=EOF) 40 { 41 if(Len_X==0&&Len_Y==0&&D==0)return 0; 42 getchar(); 43 for(i=0;i<Len_X;i++) 44 { 45 for(j=0;j<Len_Y;j++) 46 { 47 scanf("%c",&Map[i][j]); 48 if(Map[i][j]==‘S‘) 49 {Begin_x=i;Begin_y=j;} 50 if(Map[i][j]==‘D‘) 51 {End_x=i;End_y=j;} 52 } 53 getchar(); 54 } 55 SIGN=0; 56 A=(End_y-Begin_y)>0?(End_y-Begin_y):-(End_y-Begin_y); 57 B=(End_x-Begin_x)>0?(End_x-Begin_x):-(End_x-Begin_x); 58 if(D%2==(A+B)%2) 59 DFS(Begin_x,Begin_y,0,D); 60 if(SIGN!=0) 61 printf("YES\n"); 62 else 63 printf("NO\n"); 64 } 65 return 0; 66 }
Tempter of the Bone,布布扣,bubuko.com
标签:des style class blog c code
原文地址:http://www.cnblogs.com/LWF5201314614/p/3750332.html