做了好几个小时~~开始的做法是先找出C走的路径~~并记下循环节~~~然后再走F..走到一个点就判断下是不是能同时~~开了2个4维数组~~代码码了120多行~~结果还是没调出来...要吐了..
刚才突然开窍了~~这不同时记步数同时走~~啥时候一样就ok了~~~呃~~十分钟解决~~矮油~~
Program:
/* ID: zzyzzy12 LANG: C++ TASK: ttwo */ #include<iostream> #include<istream> #include<stdio.h> #include<string.h> #include<math.h> #include<stack> #include<algorithm> #include<queue> using namespace std; const int face[4][2]={{-1,0},{0,1},{1,0},{0,-1}}; char mar[12][12]; int s[12][12][12][12],c[12][12][12][12]; int y,x,step,k,ty,tx,my,mx; bool judge(int ty,int tx) { if (ty==10 || ty<0 || tx==10 || tx<0 || mar[ty][tx]=='*') return false; return true; } void choose(int *y,int *x,int *k) { ty=*y+face[*k][0]; tx=*x+face[*k][1]; if (!judge(ty,tx)) { *k=(*k+1)%4; return; } *y=ty; *x=tx; return; } int getanswer() { int step=0,ty,tx,x1,y1,x2,y2,k1=0,k2=0; for (y1=0;y1<10;y1++) { for (x1=0;x1<10;x1++) if (mar[y1][x1]=='C') break; if (x1!=10) break; } for (y2=0;y2<10;y2++) { for (x2=0;x2<10;x2++) if (mar[y2][x2]=='F') break; if (x2!=10) break; } while (step<10001) { step++; choose(&y1,&x1,&k1); choose(&y2,&x2,&k2); if (x1==x2 && y1==y2) return step; } return 0; } int main() { freopen("ttwo.in","r",stdin); freopen("ttwo.out","w",stdout); for (int i=0;i<10;i++) scanf("%s",mar[i]); printf("%d\n",getanswer()); return 0; }