USACO 2.4 The Tamworth Two(乱搞)
这个和金华的小模拟很相似,题目中啥也没说,想枚举100000秒,试一下水的。结果就水过了,1Y。
1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: ttwo 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <cmath> 10 #include <algorithm> 11 using namespace std; 12 int x[4] = {-1,0,1,0}; 13 int y[4] = {0,1,0,-1}; 14 char str[11][11]; 15 int judge(int r,int c,int d) 16 { 17 if(r+x[d] > 9||r+x[d] < 0) 18 return 0; 19 if(c+y[d] > 9||c+y[d] < 0) 20 return 0; 21 if(str[r+x[d]][c+y[d]] == '*') 22 return 0; 23 return 1; 24 } 25 int main() 26 { 27 int i,j,r1,c1,r2,c2,d1,d2; 28 freopen("ttwo.in","r",stdin); 29 freopen("ttwo.out","w",stdout); 30 for(i = 0;i <= 9;i ++) 31 scanf("%s",str[i]); 32 d1 = d2 = 0; 33 for(i = 0;i <= 9;i ++) 34 { 35 for(j = 0;j <= 9;j ++) 36 { 37 if(str[i][j] == 'F') 38 { 39 r1 = i; 40 c1 = j; 41 } 42 if(str[i][j] == 'C') 43 { 44 r2 = i; 45 c2 = j; 46 } 47 } 48 } 49 for(i = 1;i <= 100000;i ++) 50 { 51 if(judge(r1,c1,d1)) 52 { 53 r1 = r1+x[d1]; 54 c1 = c1+y[d1]; 55 } 56 else 57 d1 = (d1+1)%4; 58 if(judge(r2,c2,d2)) 59 { 60 r2 = r2+x[d2]; 61 c2 = c2+y[d2]; 62 } 63 else 64 d2 = (d2+1)%4; 65 if(r1 == r2&&c1 == c2) 66 { 67 printf("%d\n",i); 68 break; 69 } 70 } 71 if(i == 100001) 72 printf("0\n"); 73 return 0; 74 }