记录编号 |
114557 |
评测结果 |
AAAAAAAAA |
题目名称 |
[USACO 2.4]两只塔姆沃斯牛 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.010 s |
提交时间 |
2014-07-31 16:29:17 |
内存使用 |
1.52 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="ttwo";//程序名
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=='F')
{
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("0\n");
else
printf("%d\n",t);
return 0;
}
//================fuction code====================