/**//*
ID: lorelei3
TASK: ttwo
LANG: C++
*/
#include <fstream>
using namespace std;
ifstream fin;
ofstream fout;
const int MAX = 10000000;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };
int cd=0, cx, cy;
int fd=0, fx, fy;
int map[10][10];
int main(){
int i,j;
char ch;
fin.open("ttwo.in");
fout.open("ttwo.out");
for(i=0; i<10; i++)
for(j=0; j<10; j++){
fin>>ch;
if(ch=='*'){
map[i][j]=1;
}else if(ch=='C'){
cx=i, cy=j;
}else if(ch=='F'){
fx=i, fy=j;
}
}
int step=0;
int x,y;
while(step!=MAX){
// for cows
x = cx+dx[cd];
y = cy+dy[cd];
if(map[x][y]==1 || x<0 || x>9 || y<0 || y>9)
cd = (cd+1)%4;
else{
cx = x;
cy = y;
}
// for farmer
x = fx+dx[fd];
y = fy+dy[fd];
if(map[x][y]==1 || x<0 || x>9 || y<0 || y>9)
fd = (fd+1)%4;
else{
fx = x;
fy = y;
}
step++;
//compare
if(cx==fx && cy==fy)
break;
}
if(step == MAX)
fout<<0<<endl;
else
fout<<step<<endl;
return 0;
}
posted on 2010-12-08 11:18
小阮 阅读(220)
评论(0) 编辑 收藏 引用 所属分类:
USACO