标签:
一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留。
还是蛮简单的。
调试输出的话可以看到具体追击过程
Source Code:
/* ID: wushuai2 PROG: ttwo LANG: C++ */ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <stack> #include <string> #include <map> #include <set> #include <list> #include <queue> #include <vector> #include <algorithm> #define Max(a,b) (((a) > (b)) ? (a) : (b)) #define Min(a,b) (((a) < (b)) ? (a) : (b)) #define Abs(x) (((x) > 0) ? (x) : (-(x))) #define MOD 1000000007 #define pi acos(-1.0) #define RV(num) ((num) > 0 ? 0 : 1) using namespace std; typedef long long ll ; typedef unsigned long long ull ; typedef unsigned int uint ; typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;} template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e-7 ; const int M = 660000 ; const ll P = 10000000097ll ; const int INF = 0x3f3f3f3f ; const int MAX_N = 20 ; const int MAXSIZE = 101000000; ofstream fout ("ttwo.out"); ifstream fin ("ttwo.in"); int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; char gra[11][11]; int dir_f, dir_c; struct sc{ int x, y; }pos[2], nxt_pos[2], sta[2]; bool check(int x, int y){ if(x >= 1 && x <= 10 && y >= 1 && y <= 10){ if(gra[x][y] != ‘*‘){ return true; } } return false; } bool finish(){ if(pos[0].x == pos[1].x && pos[1].y == pos[0].y){ return true; } else return false; } int main(){ int i, j, k, l, m, n, t, s, c, w, q, u, v, num, val; for(i = 1; i <= 10; ++i){ for(j = 1; j <= 10; ++j){ fin >> gra[i][j]; if(gra[i][j] == ‘F‘){ sta[0].x = i, sta[0].y = j; //pos[0].x = i, pos[0].y = j; } else if(gra[i][j] == ‘C‘){ sta[1].x = i, sta[1].y = j; //pos[1].x = i, pos[1].y = j; } } } int ans = 1; int dir_f = 0; int dir_c = 0; pos[0] = sta[0], pos[1] = sta[1]; for(;;){ /* for(i = 1; i <= 10; ++i){ for(j = 1; j <= 10; ++j){ if(pos[0].x == i && pos[0].y == j){ fout << ‘F‘; } else if(pos[1].x == i && pos[1].y == j){ fout << ‘C‘; } else if(gra[i][j] == ‘*‘) fout << ‘*‘; else fout << ‘.‘; } fout << endl; } fout << endl; */ nxt_pos[0].x = pos[0].x + dir[dir_f][0]; nxt_pos[0].y = pos[0].y + dir[dir_f][1]; nxt_pos[1].x = pos[1].x + dir[dir_c][0]; nxt_pos[1].y = pos[1].y + dir[dir_c][1]; if(check(nxt_pos[0].x, nxt_pos[0].y) && check(nxt_pos[1].x, nxt_pos[1].y)){ pos[0] = nxt_pos[0], pos[1] = nxt_pos[1]; } else if(!check(nxt_pos[0].x, nxt_pos[0].y) && !check(nxt_pos[1].x, nxt_pos[1].y)){ dir_f = (dir_f + 1) % 4; dir_c = (dir_c + 1) % 4; } else if(check(nxt_pos[0].x, nxt_pos[0].y) && !check(nxt_pos[1].x, nxt_pos[1].y)){ dir_c = (dir_c + 1) % 4; pos[0] = nxt_pos[0]; } else if(!check(nxt_pos[0].x, nxt_pos[0].y) && check(nxt_pos[1].x, nxt_pos[1].y)){ dir_f = (dir_f + 1) % 4; pos[1] = nxt_pos[1]; } if(finish()){ break; } ++ans; if(ans > 10000){ ans = 0; break; } } fout << ans << endl; fin.close(); fout.close(); return 0; }
标签:
原文地址:http://www.cnblogs.com/wushuaiyi/p/4298569.html