P5380WA on #2 求调,玄关
查看原帖
P5380WA on #2 求调,玄关
950799
Chiesl楼主2024/8/14 16:05

代码如下,蒟蒻自认马蜂良好:

#include<bits/stdc++.h>
using namespace std;
bool is_died;
string name[20] = {"就是歌姬", "car", "horse", "elephant", "guard", "captain", "soldier", "duck", "car", "horse", "elephant", "guard", "captain", "soldier", "duck"};
//                     0         1       2          3         4         5          6         7      (1至7红方,其余为蓝方) 
const int move_cnt[] = {0, 0, 8, 4, 4, 4, 8, 8, 0, 8, 4, 4, 4, 8, 8};
const int dx[20][10] = {
	{5, 4, 1, 8, 8},
	{-114514},
	{-1, -2, -2, -1, 1, 2, 2, 1},
	{-2, -2, 2, 2},
	{-1, -1, 1, 1},
	{-1, 1, 0, 0},
	{-1, -1, -1, 0, 1, 1, 1, 0},	
	{-2, -3, -3, -2, 2, 3, 3, 2},
	{-114514},
	{-1, -2, -2, -1, 1, 2, 2, 1},
	{-2, -2, 2, 2},
	{-1, -1, 1, 1},
	{-1, 1, 0, 0},
	{-1, -1, -1, 0, 1, 1, 1, 0},	
	{-2, -3, -3, -2, 2, 3, 3, 2},			
};
const int dy[20][10] = {
	{5, 4, 1, 8, 8},
	{-114514},
	{-2, -1, 1, 2, 2, 1, -1, -2},
	{-2, 2, 2, -2},
	{-1, 1, 1, -1},
	{0, 0, -1, 1},
	{-1, 0, 1, 1, 1, 0, -1, -1},	
	{-3, -2, 2, 3, 3, 2, -2, -3},
	{-114514},
	{-2, -1, 1, 2, 2, 1, -1, -2},
	{-2, 2, 2, -2},
	{-1, 1, 1, -1},
	{0, 0, -1, 1},
	{-1, 0, 1, 1, 1, 0, -1, -1},	
	{-3, -2, 2, 3, 3, 2, -2, -3},
};
int board[12][12] = 
{
	{1 , 2 , 3 , 4 , 5 , 4 , 3 , 2 , 1 },
	{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
	{7 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 }, 
	{6 , 0 , 6 , 0 , 6 , 0 , 6 , 0 , 6 },
	{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
	{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, 
	{13, 0 , 13, 0 , 13, 0 , 13, 0 , 13},
	{14, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 14}, 
	{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
	{8 , 9 , 10, 11, 12, 11, 10, 9 , 8 },				
};
inline bool camp_judge (int x, int y) {return x / 8 == y / 8;}
inline bool check () {
	for (int x = 0; x < 10; x++) {
		for (int y = 0; y < 9; y++) {
			if (!board[x][y]) continue;
			int v = board[x][y];
			if (v == 1) {
				int nx = x, ny = y;
				while (--nx >= 0) {
					if (board[nx][ny]) {
						if (camp_judge(v, board[nx][ny])) break;
						if (name[board[nx][ny]] != "captain") break;
						return true;
					}
				}
				nx = x;
				while (++nx < 10) {
					if (board[nx][ny]) {
						if (camp_judge(v, board[nx][ny])) break;
						if (name[board[nx][ny]] != "captain") break;
						return true;
					}
				}
				nx = x;
				while (--ny >= 0) {
					if (board[nx][ny]) {
						if (camp_judge(v, board[nx][ny])) break;
						if (name[board[nx][ny]] != "captain") break;
						return true;
					}
				}
				ny = y;	
				while (++ny < 9) {
					if (board[nx][ny]) {
						if (camp_judge(v, board[nx][ny])) break;
						if (name[board[nx][ny]] != "captain") break;
						return true;
					}
				}										
			}
			for (int k = 0; k < move_cnt[v]; k++) {
				int nx = x + dx[v][k], ny = y + dy[v][k];
				if (nx < 0 || nx > 9 || ny < 0 || ny > 8) continue;
				if (!board[nx][ny]) continue;
				if (camp_judge(v, board[nx][ny])) continue;
				if (v % 7 == 3 && board[x + dx[4][k]][y + dy[4][k]]) continue;
				if (v % 7 == 2) {
					if ((k == 0 || k == 7) && board[x][y - 1]) continue;
					if ((k == 1 || k == 2) && board[x - 1][y]) continue;
					if ((k == 3 || k == 4) && board[x][y + 1]) continue;
					if ((k == 5 || k == 6) && board[x + 1][y]) continue;
				}
				if (v % 7 == 0) {
					if (board[x + dx[2][k]][y + dy[2][k]]) continue;
					if ((k == 0 || k == 7) && board[x][y - 1]) continue;
					if ((k == 1 || k == 2) && board[x - 1][y]) continue;
					if ((k == 3 || k == 4) && board[x][y + 1]) continue;
					if ((k == 5 || k == 6) && board[x + 1][y]) continue;					
				}				
				if (name[board[nx][ny]] == "captain") return true;
			}
		}
	}
	return false;
}
int main () {
	int question_cnt, sx, sy, ex, ey, now = 0;
	scanf("%d", &question_cnt);
	while (question_cnt--) {
		scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
		if (is_died) {
			printf("Invalid command\n");
			continue;			
		}
		if (sx < 0 || sx > 9 || sy < 0 || sy > 8) {
			printf("Invalid command\n");
			continue;
		}
		if (ex < 0 || ex > 9 || ey < 0 || ey > 8) {
			printf("Invalid command\n");
			continue;
		}
		if (!board[sx][sy]) {
			printf("Invalid command\n");
			continue;
		}
		if (board[ex][ey] && camp_judge(board[ex][ey], board[sx][sy])) {
			printf("Invalid command\n");
			continue;
		}
		if (now != board[sx][sy] / 8) {
			printf("Invalid command\n");
			continue;
		}
		int now_chess = board[sx][sy];
		if (now_chess == 1) {
			if (sx != ex && sy != ey) {
				printf("Invalid command\n");
				continue;
			}
			bool flag = true;
			if (sx == ex) {
				if (sy < ey) {
					for (int i = sy + 1; i < ey; i++) {
						if (board[sx][i]) {
							flag = false;
							break;
						}
					}
				} else {
					for (int i = ey + 1; i < sy; i++) {
						if (board[sx][i]) {
							flag = false;
							break;
						}
					}
				}
			} else {
				if (sx < ex) {
					for (int i = sx + 1; i < ex; i++) {
						if (board[i][sy]) {
							flag = false;
							break;
						}
					}
				} else {
					for (int i = ex + 1; i < sx; i++) {
						if (board[i][sy]) {
							flag = false;
							break;
						}
					}
				}				
			}
			if (!flag) {
				printf("Invalid command\n");
				continue;				
			}
		}
		bool flag = false;
		for (int i = 0; i < move_cnt[now_chess]; i++) {
			int nx = sx + dx[now_chess][i], ny = sy + dy[now_chess][i];
			if (nx < 0 || nx > 9 || ny < 0 | ny > 9) continue;
			if (nx == ex && ny == ey) {
				if (now_chess % 7 == 3 && board[sx + dx[4][i]][sy + dy[4][i]]) break;
				if (now_chess % 7 == 2) {
					if ((i == 0 || i == 7) && board[sx][sy - 1]) break;
					if ((i == 1 || i == 2) && board[sx - 1][sy]) break;
					if ((i == 3 || i == 4) && board[sx][sy + 1]) break;
					if ((i == 5 || i == 6) && board[sx + 1][sy]) break;
				}
				if (now_chess % 7 == 0) {
					if (board[sx + dx[2][i]][sy + dy[2][i]]) break;
					if ((i == 0 || i == 7) && board[sx][sy - 1]) break;
					if ((i == 1 || i == 2) && board[sx - 1][sy]) break;
					if ((i == 3 || i == 4) && board[sx][sy + 1]) break;
					if ((i == 5 || i == 6) && board[sx + 1][sy]) break;					
				}
				flag = true;
				break;
			}
		}
		if (!flag) {
			printf("Invalid command\n");
			continue;				
		}
		cout << (now_chess / 8 ? "blue" : "red") << ' ' << name[now_chess] << ';';
		if (!board[ex][ey]) cout << "NA" << ';';
		else cout << (board[ex][ey] / 8 ? "blue" : "red") << ' ' << name[board[ex][ey]] << ';';
		if (board[ex][ey] == 5 || board[ex][ey] == 12) is_died = true;
		board[sx][sy] = 0, board[ex][ey] = now_chess;
		if (!is_died && check()) printf("yes;");
		else printf("no;");
		if (is_died) printf("yes\n");
		else printf("no\n");
		now ^= 1;
	}
	return 0;
}
2024/8/14 16:05
加载中...