p1518 The Tamworth Two

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-8;
typedef long long lon;
const lon SZ=12,INF=0x7FFFFFFF,mod=9901;
char ch[SZ][SZ];
bool vst[SZ][SZ][4][SZ][SZ][4];
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //for(lon time=1;time<=casenum;++time)
    {
        for(int i=1;i<=10;++i)cin>>ch[i]+1;
        int fx,fy,cx,cy;
        for(int i=1;i<=10;++i)
        {
            for(int j=1;j<=10;++j)
            {
                if(ch[i][j]=='F')fx=i,fy=j;
                if(ch[i][j]=='C')cx=i,cy=j;
            }
        }
        vst[fx][fy][0][cx][cy][0]=1;
        int dc=0,df=0;
        int time=0;
        //cout<<fx<<" "<<fy<<" "<<cx<<" "<<cy<<endl;
        for(;;)
        {
            int nfx=fx+dx[df],nfy=fy+dy[df];
            int ncx=cx+dx[dc],ncy=cy+dy[dc];
            if(nfx>=1&&nfx<=10&&nfy>=1&&nfy<=10&&ch[nfx][nfy]!='*')
            {
                fx=nfx,fy=nfy;
            }
            else df=(df+1)%4;
            if(ncx>=1&&ncx<=10&&ncy>=1&&ncy<=10&&ch[ncx][ncy]!='*')
            {
                cx=ncx,cy=ncy;
            }
            else dc=(dc+1)%4;
            ++time;
            if(fx==cx&&fy==cy)
            {
                cout<<time<<endl;
                break;
            }
            if(vst[fx][fy][df][cx][cy][dc]==1)
            {//cout<<fx<<" "<<fy<<" "<<cx<<" "<<cy<<endl;
                cout<<0<<endl;
                break;
            }
            vst[fx][fy][df][cx][cy][dc]=1;
        }
    }
    return 0;
}

 

posted @ 2018-10-21 21:03  degvx  阅读(144)  评论(0)    收藏  举报