一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留。
还是蛮简单的。
调试输出的话可以看到具体追击过程
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- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ;
const int MAXSIZE = ; ofstream fout ("ttwo.out");
ifstream fin ("ttwo.in"); int dir[][] = {{-, }, {, }, {, }, {, -}};
char gra[][];
int dir_f, dir_c; struct sc{
int x, y;
}pos[], nxt_pos[], sta[]; bool check(int x, int y){
if(x >= && x <= && y >= && y <= ){
if(gra[x][y] != '*'){
return true;
}
}
return false;
} bool finish(){
if(pos[].x == pos[].x && pos[].y == pos[].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 = ; i <= ; ++i){
for(j = ; j <= ; ++j){
fin >> gra[i][j];
if(gra[i][j] == 'F'){
sta[].x = i, sta[].y = j;
//pos[0].x = i, pos[0].y = j;
} else if(gra[i][j] == 'C'){
sta[].x = i, sta[].y = j;
//pos[1].x = i, pos[1].y = j;
}
}
}
int ans = ;
int dir_f = ;
int dir_c = ;
pos[] = sta[], pos[] = sta[];
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[].x = pos[].x + dir[dir_f][];
nxt_pos[].y = pos[].y + dir[dir_f][];
nxt_pos[].x = pos[].x + dir[dir_c][];
nxt_pos[].y = pos[].y + dir[dir_c][];
if(check(nxt_pos[].x, nxt_pos[].y) && check(nxt_pos[].x, nxt_pos[].y)){
pos[] = nxt_pos[], pos[] = nxt_pos[];
} else if(!check(nxt_pos[].x, nxt_pos[].y) && !check(nxt_pos[].x, nxt_pos[].y)){
dir_f = (dir_f + ) % ;
dir_c = (dir_c + ) % ;
} else if(check(nxt_pos[].x, nxt_pos[].y) && !check(nxt_pos[].x, nxt_pos[].y)){
dir_c = (dir_c + ) % ;
pos[] = nxt_pos[];
} else if(!check(nxt_pos[].x, nxt_pos[].y) && check(nxt_pos[].x, nxt_pos[].y)){
dir_f = (dir_f + ) % ;
pos[] = nxt_pos[];
}
if(finish()){
break;
}
++ans;
if(ans > ){
ans = ;
break;
}
} fout << ans << endl;
fin.close();
fout.close();
return ;
}