我下载了 #1 数据,在 DEVC++ 中运行是正确的。
#include<bits/stdc++.h>
#define len 10
#define maxl 19
#define maxt 1000000
using namespace std;
char mp[maxl][maxl];
int dx[5]={-1,0,1,0};
int dy[5]={0,1,0,-1};
int tzz,mcx,mcy,mfx,mfy,ans;
char p;
bool tz[maxt];//c.x+c.y*10+f.x*100+f.y*1000+c.face*10000+f.face*40000
struct cow{
int x;
int y;
int face;
}c;
struct farm{
int x;
int y;
int face;
}f;
int main(){
c.face=0;
f.face=0;
for(int i=0;i<=len;i++){
mp[0][i]=mp[i][0]='*';
}
for(int i=0;i<=len;i++){
mp[11][i]=mp[i][11]='*';
}
for(int i=1;i<=len;i++){
for(int j=1;j<=len;j++){
mp[i][j]=getchar();
if(mp[i][j]=='C'){
c.x=i;
c.y=j;
}
if(mp[i][j]=='F'){
f.x=i;
f.y=j;
}
}
if(i<len) p=getchar();
}
while(114514){
if(f.x==c.x&&f.y==c.y){
cout<<ans<<endl;
return 0;
}
tzz=c.x+c.y*10+f.x*100+f.y*1000+c.face*10000+f.face*40000;
if(tz[tzz]){
cout<<0<<endl;
return 0;
}
tz[tzz]=true;
mcx=c.x+dx[c.face];
mfx=f.x+dx[f.face];
mcy=c.y+dy[c.face];
mfy=f.y+dy[f.face];
if(mp[mcx][mcy]=='*') c.face=(c.face+1)%4;
else{
c.x=mcx;
c.y=mcy;
}
if(mp[mfx][mfy]=='*') f.face=(f.face+1)%4;
else{
f.x=mfx;
f.y=mfy;
}
ans++;
}
return 0;
}