#6和#8TLE了,应该是无法判断死循环,但我做了判定,代码如下,请大佬多多指教 那些if应该不是导致TLE的原因,下面的代码我用了些“小窍门”就a了
#include<bits/stdc++.h>
using namespace std;
int fx,fy,cx,cy,fx0,fy0,cx0,cy0,f=1,c=1,t=0,t1;
char a[11][11],t2;
int move(){
++t;
if(f==1 && a[fx-1][fy]!='*' && fx-1>=1) --fx;
else if(f==2 && a[fx][fy+1]!='*' && fy+1<=10) ++fy;
else if(f==3 && a[fx+1][fy]!='*' && fx+1<=10) ++fx;
else if(f==4 && a[fx][fy-1]!='*' && fy-1>=1) --fy;
else ++f;
if(f>4) f-=4;
if(c==1 && a[cx-1][cy]!='*' && cx-1>=1) --cx;
else if(c==2 && a[cx][cy+1]!='*' && cy+1<=10) ++cy;
else if(c==3 && a[cx+1][cy]!='*' && cx+1<=10) ++cx;
else if(c==4 && a[cx][cy-1]!='*' && cy-1>=1) --cy;
else ++c;
if(c>4) c-=4;
if(fx==cx && fy==cy) return 1;
else if(fx==fx0 && fy==fy0 && cx==cx0 && cy==cy0 && t!=1) return -1;
return 0;
}
int main(){
for(int i=1;i<=10;++i){
for(int j=1;j<=10;++j){
while(a[i][j]!='.' && a[i][j]!='*' && a[i][j]!='C' && a[i][j]!='F') scanf("%c",&a[i][j]);
if(a[i][j]=='F') fx0=i,fy0=j;
else if(a[i][j]=='C') cx0=i,cy0=j;
}
}fx=fx0,fy=fy0,cx=cx0,cy=cy0;
while(t<200000000){//实在没办法了卡1s的时限,超时无结果认为无解
t1=move();
if(t1==1){
cout<<t;
return 0;
}else if(t1==-1){
cout<<0;
return 0;
}
}cout<<0;
return 0;
}