QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#399817#2821. 鸭棋ucup-team1251WA 1ms3600kbC++1711.1kb2024-04-26 17:59:042024-04-26 17:59:05

Judging History

你现在查看的是最新测评结果

  • [2024-04-26 17:59:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2024-04-26 17:59:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

struct node
{
	int x, y;
};
int mp[10][9] =
{
	{5, 4, 3, 2, 1, 2, 3, 4, 5},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{6, 0, 0, 0, 0, 0, 0, 0, 6},
	{7, 0, 7, 0, 7, 0, 7, 0, 7},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{7, 0, 7, 0, 7, 0, 7, 0, 7},
	{6, 0, 0, 0, 0, 0, 0, 0, 6},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{5, 4, 3, 2, 1, 2, 3, 4, 5},
};
int col[10][9] =
{
	{1, 1, 1, 1, 1, 1, 1, 1, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{1, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 1, 0, 1, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{2, 0, 2, 0, 2, 0, 2, 0, 2},
	{2, 0, 0, 0, 0, 0, 0, 0, 2},
	{0, 0, 0, 0, 0, 0, 0, 0, 0},
	{2, 2, 2, 2, 2, 2, 2, 2, 2},
};


int getnow(int now)
{
	now++;
	if (now == 3) now = 1;
	return now;
}

int dx[8][10] =
{
	{},
	{0, 0, 1, -1},
	{1, 1, -1, -1},
	{1, 1, -1, -1},
	{1, 1, -1, -1, 2, 2, -2, -2},
	{},
	{2, 2, 3, 3, -2, -2, -3, -3},
	{-1, -1, -1, 0, 0, 1, 1, 1}
};

int dy[8][10] =
{
	{},
	{1, -1, 0, 0},
	{1, -1, 1, -1},
	{1, -1, 1, -1},
	{2, -2, 2, -2, 1, -1, 1, -1},
	{},
	{3, -3, 2, -2, 3, -3, 2, -2},
	{-1, 0, 1, -1, 1, -1, 0, 1}
};

int bx[8][10]
{
	{},
	{},
	{},
	{},
	{0, 0, 0, 0, 1, 1, -1, -1},
	{},
	{0, 0, 1, 1, 0, 0, -1, -1},
	{1, 1, 2, 2, -1, -1, -2, -2}
};

int by[8][10]
{
	{},
	{},
	{},
	{},
	{1, -1, 1, -1, 0, 0, 0, 0},
	{},
	{1, -1, 0, 0, 1, -1, 0, 0},
	{2, -2, 1, -1, 2, -2, 1, -1}
};

bool ok(int x, int y)
{
	if (x < 0 || x >= 10 || y < 0 || y >= 9)
	{
		return false;
	}
	return true;
}



bool checkmate()
{
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 9; j++)
		{
			if (mp[i][j])
			{
				if (mp[i][j] == 1)
				{
					for (int k = 0; k < 4; k++)
					{
						int xx = i + dx[1][k], yy = j + dy[1][k];
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
				else if (mp[i][j] == 2)
				{
					for (int k = 0; k < 4; k++)
					{
						int xx = i + dx[2][k], yy = j + dy[2][k];
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
				else if (mp[i][j] == 3)
				{
					for (int k = 0; k < 4; k++)
					{
						int xx = i + 2 * dx[3][k], yy = j + 2 * dy[3][k];
						if (ok(xx, yy) && !mp[i + dx[3][k]][j + dy[3][k]])
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
				else if (mp[i][j] == 4)     //马
				{
					for (int k = 0; k < 8; k++)
					{
						int xx = i + dx[4][k], yy = j + dy[4][k];
						if (ok(xx, yy) && !mp[i + bx[4][k]][j + by[4][k]])
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
				else if (mp[i][j] == 5)     //che
				{
					for (int k = 1; k <= 10; k++)
					{
						int xx = i + k, yy = j;
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
					for (int k = 1; k <= 9; k++)
					{
						int xx = i, yy = j + k;
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
					for (int k = -1; k >= -10; k--)
					{
						int xx = i + k, yy = j;
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
					for (int k = -1; k >= -9; k--)
					{
						int xx = i, yy = j + k;
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
				else if (mp[i][j] == 6)
				{
					for (int k = 0; k < 8; k++)
					{
						int xx = i + dx[6][k], yy = j + dy[6][k];
						if (ok(xx, yy) && mp[i + bx[6][k]][j + by[6][k]] && mp[i + bx[7][k]][j + by[7][k]])
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
				else if (mp[i][j] == 7)
				{
					for (int k = 0; k < 8; k++)
					{
						int xx = i + dx[7][k], yy = j + dy[7][k];
						if (ok(xx, yy))
						{
							if (mp[xx][yy] == 1 && col[xx][yy] != col[i][j])
							{
								return true;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

bool over()
{
	int king = 0;
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 9; j++)
		{
			if (mp[i][j] == 1)
			{
				king++;
			}
		}
	}
	if (king < 2)
	{
		return 1;
	}
	return 0;
}

bool pd(int x1, int y1, int x2, int y2)
{
	if (mp[(x1 + x2 + 1) / 2][(y1 + y2 + 1) / 2])
	{
		return false;
	}
	int xx, yy;
	if (abs(x2 - x1) == 3)
	{
		if (x2 > x1)xx = x1 + 1;
		else xx = x1 - 1;
		yy = y1;
	}
	else
	{
		if (y2 < y1)yy = y1 - 1;
		else yy = y1 + 1;
		xx = x1;
	}
	if (mp[xx][yy])return false;
	return true;
}

string outcol[3] = {" ", "red", "blue"};
string outq[8] = {" ", "captain", "guard", "elephant", "horse", "car", "duck", "soldier"};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	int q, now = 1;
	cin >> q;
	while (q--)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (col[x1][y1] == now && col[x2][y2] != now)
		{
			if (mp[x1][y1] == 1) //王
			{
				if ((x2 == x1 && abs(y2 - y1) == 1) || (y2 == y1 && abs(x2 - x1) == 1))
				{
					cout << outcol[now] << " " << outq[1] << ";";
					if (mp[x2][y2])
					{
						cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
					}
					else
					{
						cout << "NA;";
					}
					col[x2][y2] = now;
					now = getnow(now);
					mp[x2][y2] = 1;
					mp[x1][y1] = 0;
					col[x1][y1] = 0;
					if (checkmate())
					{
						cout << "yes;";
					}
					else
					{
						cout << "no;";
					}
					if (over())
					{
						cout << "yes";
					}
					else
					{
						cout << "no";
					}
					cout << "\n";
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
			else if (mp[x1][y1] == 2) //士
			{
				if (abs(x1 - x2) == 1 && abs(y2 - y1) == 1)
				{
					cout << outcol[now] << " " << outq[2] << ";";
					if (mp[x2][y2])
					{
						cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
					}
					else
					{
						cout << "NA;";
					}
					col[x2][y2] = now;
					now = getnow(now);
					mp[x2][y2] = 2;
					mp[x1][y1] = 0;
					col[x1][y1] = 0;
					if (checkmate())
					{
						cout << "yes;";
					}
					else
					{
						cout << "no;";
					}
					if (over())
					{
						cout << "yes";
					}
					else
					{
						cout << "no";
					}
					cout << "\n";
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
			else if (mp[x1][y1] == 3)
			{
				if (abs(x1 - x2) == 2 && abs(y2 - y1) == 2 && !mp[(x1 + x2) / 2][(y1 + y2) / 2])
				{
					cout << outcol[now] << " " << outq[3] << ";";
					if (mp[x2][y2])
					{
						cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
					}
					else
					{
						cout << "NA;";
					}
					col[x2][y2] = now;
					now = getnow(now);
					mp[x2][y2] = 3;
					mp[x1][y1] = 0;
					col[x1][y1] = 0;
					if (checkmate())
					{
						cout << "yes;";
					}
					else
					{
						cout << "no;";
					}
					if (over())
					{
						cout << "yes";
					}
					else
					{
						cout << "no";
					}
					cout << "\n";
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
			else if (mp[x1][y1] == 4)
			{
				if (((abs(x1 - x2) == 1 && abs(y2 - y1) == 2) || (abs(x1 - x2) == 2 && abs(y2 - y1) == 1)) && !mp[(x1 + x2) / 2][(y1 + y2) / 2])
				{
					cout << outcol[now] << " " << outq[4] << ";";
					if (mp[x2][y2])
					{
						cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
					}
					else
					{
						cout << "NA;";
					}
					col[x2][y2] = now;
					now = getnow(now);
					mp[x2][y2] = 4;
					mp[x1][y1] = 0;
					col[x1][y1] = 0;
					if (checkmate())
					{
						cout << "yes;";
					}
					else
					{
						cout << "no;";
					}
					if (over())
					{
						cout << "yes";
					}
					else
					{
						cout << "no";
					}
					cout << "\n";
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
			else if (mp[x1][y1] == 5)
			{
				if (x2 == x1)
				{
					int f = 0;
					for (int j = min(y1, y2) + 1; j < max(y1, y2); j++)
					{
						if (mp[x1][j])
						{
							f = 1;
							break;
						}
					}
					if (f)
					{
						cout << "Invalid command\n";
					}
					else
					{
						cout << outcol[now] << " " << outq[5] << ";";
						if (mp[x2][y2])
						{
							cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
						}
						else
						{
							cout << "NA;";
						}
						col[x2][y2] = now;
						now = getnow(now);
						mp[x2][y2] = 5;
						mp[x1][y1] = 0;
						col[x1][y1] = 0;
						if (checkmate())
						{
							cout << "yes;";
						}
						else
						{
							cout << "no;";
						}
						if (over())
						{
							cout << "yes";
						}
						else
						{
							cout << "no";
						}
						cout << "\n";
					}
				}
				else if (y2 == y1)
				{
					int f = 0;
					for (int i = min(x1, x2) + 1; i < max(x1, x2); i++)
					{
						if (mp[i][y1])
						{
							f = 1;
							break;
						}
					}
					if (f)
					{
						cout << "Invalid command\n";
					}
					else
					{
						cout << outcol[now] << " " << outq[5] << ";";
						if (mp[x2][y2])
						{
							cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
						}
						else
						{
							cout << "NA;";
						}
						col[x2][y2] = now;
						now = getnow(now);
						mp[x2][y2] = 5;
						mp[x1][y1] = 0;
						col[x1][y1] = 0;
						if (checkmate())
						{
							cout << "yes;";
						}
						else
						{
							cout << "no;";
						}
						if (over())
						{
							cout << "yes";
						}
						else
						{
							cout << "no";
						}
						cout << "\n";
					}
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
			else if (mp[x1][y1] == 6)
			{
				if (((abs(x1 - x2) == 2 && abs(y2 - y1) == 3) || (abs(x1 - x2) == 3 && abs(y2 - y1) == 2)) && pd(x1, y1, x2, y2))
				{
					cout << outcol[now] << " " << outq[6] << ";";
					if (mp[x2][y2])
					{
						cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
					}
					else
					{
						cout << "NA;";
					}
					col[x2][y2] = now;
					now = getnow(now);
					mp[x2][y2] = 6;
					mp[x1][y1] = 0;
					col[x1][y1] = 0;
					if (checkmate())
					{
						cout << "yes;";
					}
					else
					{
						cout << "no;";
					}
					if (over())
					{
						cout << "yes";
					}
					else
					{
						cout << "no";
					}
					cout << "\n";
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
			else
			{
				if ((abs(x2 - x1) >= 0 && abs(x2 - x1) <= 1) && (abs(y2 - y1) >= 0 && abs(y2 - y1) <= 1))
				{
					cout << outcol[now] << " " << outq[7] << ";";
					if (mp[x2][y2])
					{
						cout << outcol[col[x2][y2]] << " " << outq[mp[x2][y2]] << ";";
					}
					else
					{
						cout << "NA;";
					}
					col[x2][y2] = now;
					now = getnow(now);
					mp[x2][y2] = 7;
					mp[x1][y1] = 0;
					col[x1][y1] = 0;
					if (checkmate())
					{
						cout << "yes;";
					}
					else
					{
						cout << "no;";
					}
					if (over())
					{
						cout << "yes";
					}
					else
					{
						cout << "no";
					}
					cout << "\n";
				}
				else
				{
					cout << "Invalid command\n";
				}
			}
		}
		else
			cout << "Invalid command\n";
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3600kb

input:

18
0 0 7 0
9 0 8 0
0 1 1 3
0 2 2 0
0 3 1 2
0 4 0 3
9 4 8 4
3 2 2 3
7 0 4 2
7 0 5 3
9 2 7 4
2 0 4 3
9 1 8 3
4 3 6 6
7 4 9 2
8 4 9 4
6 6 9 4
9 8 8 8

output:

Invalid command
Invalid command
Invalid command
Invalid command
red guard;NA;no;no
Invalid command
blue captain;NA;no;no
red soldier;NA;no;no
Invalid command
Invalid command
blue elephant;NA;no;no
red duck;NA;no;no
blue horse;NA;no;no
red duck;blue soldier;no;no
Invalid command
blue captain;NA;no;no...

result:

wrong answer 16th lines differ - expected: 'blue captain;NA;yes;no', found: 'blue captain;NA;no;no'