记录编号 |
119171 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[湖北2011寒假] 猫和老鼠 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.033 s |
提交时间 |
2014-09-11 16:02:48 |
内存使用 |
1.37 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
bool exist[15][15][5][15][15][5];
bool farm[20][20];
int cowr,cowl,farmr,farml,cowp=0,farmp=0;
int mover[4]={-1,0,1,0};
int movel[4]={0,1,0,-1};
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="cat";//程序名
string FloderName="USACO";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
#endif
char ch;
memset(farm,false,sizeof(farm));
memset(exist,false,sizeof(exist));
for(int row=1;row<=10;row++)
{
for(int line=1;line<=10;line++)
{
ch=getchar();
if (ch!='*')
farm[row][line]=true;
if (ch=='M')
{
farml=line;
farmr=row;
}
if (ch=='C')
{
cowl=line;
cowr=row;
}
}
cin.ignore(10,10);
}
//cowr,cowl,cowp,farmr,farml,farmp
int t=0;
while (!(exist[cowr][cowl][cowp][farmr][farml][farmp]||(cowr==farmr&&cowl==farml)))
{
exist[cowr][cowl][cowp][farmr][farml][farmp]=true;
if (farm[cowr+mover[cowp]][cowl+movel[cowp]])
{
cowr+=mover[cowp];
cowl+=movel[cowp];
}
else
cowp=(cowp+1)%4;
if (farm[farmr+mover[farmp]][farml+movel[farmp]])
{
farmr+=mover[farmp];
farml+=movel[farmp];
}
else
farmp=(farmp+1)%4;
t++;
}
if (!(cowr==farmr&&cowl==farml))
pritnf("-1\n");
else
printf("%d\n",t);
return 0;
}
//================fuction code====================