显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
const short RUL[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
char map[20][20];
bool used[10][10][4][10][10][4];
int main(void)
{
freopen("ttwo.in","r",stdin);
freopen("ttwo.out","w",stdout);
int i,j,cx,cy,cd,fx,fy,fd,tim,tx,ty;
for (i=1;i<=10;i++)
for (j=1;j<=10;j++)
{
cin>>map[i][j];
if (map[i][j]=='C')
{
map[i][j]='.';
cx=i;
cy=j;
cd=0;
}
if (map[i][j]=='F')
{
map[i][j]='.';
fx=i;
fy=j;
fd=0;
}
}
tim=0;
used[cx-1][cy-1][cd][fx-1][fy-1][fd]=1;
while (1==1)
{
tim++;
tx=cx+RUL[cd][0];
ty=cy+RUL[cd][1];
if (map[tx][ty]=='.')
{
cx=tx;
cy=ty;
}
else
{
cd=(cd+1)%4;
}
tx=fx+RUL[fd][0];
ty=fy+RUL[fd][1];
if (map[tx][ty]=='.')
{
fx=tx;
fy=ty;
}
else
{
fd=(fd+1)%4;
}
if (used[cx-1][cy-1][cd][fx-1][fy-1][fd])
{
cout<<"0\n";
return(0);
}
else
{
used[cx-1][cy-1][cd][fx-1][fy-1][fd]=1;
}
if (cx==fx&&cy==fy)
{
cout<<tim<<endl;
return(0);
}
}
return(0);
}