QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549509 | #2821. 鸭棋 | Flying_hq | AC ✓ | 1ms | 3676kb | C++14 | 17.2kb | 2024-09-06 16:38:59 | 2024-09-06 16:38:59 |
Judging History
answer
#include <bits/stdc++.h>
// #pragma GCC optimize(2)
#define int long long
#define pii pair<int, int>
#define tpi tuple<int, int, int, int>
#define il inline
#define p_q priority_queue
#define u_m unordered_map
#define bt bitset
#define rg register
#define rep(i, x, y) for (int i = (x); i <= (y); i++)
#define per(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
const int N1 = 300005;
const int N2 = 1000006;
const int mod = 998244353;
using i64 = long long;
void chmin(int& x, int c) {
x = min(x, c);
}
void chmax(int& x, int c) {
x = max(x, c);
}
namespace fast_IO {
#define IOSIZE 100000
int precision = 3, POW[10] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000
};
char ibuf[IOSIZE], obuf[IOSIZE], *p1 = ibuf, *p2 = ibuf, *p3 = obuf;
// #ifdef ONLINE_JUDGE
// #define getchar() \
// ((p1 == p2) and \
// (p2 = (p1 = ibuf) + fread(ibuf, 1, IOSIZE, stdin), p1 == p2) \
// ? (EOF) \
// : (*p1++))
// #define putchar(x)
// ((p3 == obuf + IOSIZE) && (fwrite(obuf, p3 - obuf, 1, stdout), p3 =
// obuf),
// *p3++ = x)
// #define isdigit(ch) (ch > 47 && ch < 58)
// #define isspace(ch) (ch < 33)
// #endif
template <typename T>
inline T read() {
T s = 0;
int w = 1;
char ch;
while (ch = getchar(), !isdigit(ch) && (ch != EOF))
if (ch == 45)
w = -1;
if (ch == EOF)
return 0;
while (isdigit(ch))
s = s * 10 + ch - 48, ch = getchar();
return s * w;
}
template <typename T>
inline bool read(T& s) {
s = 0;
int w = 1;
char ch;
while (ch = getchar(), !isdigit(ch) && (ch != EOF))
if (ch == 45)
w = -1;
if (ch == EOF)
return 0;
while (isdigit(ch))
s = s * 10 + ch - 48, ch = getchar();
return s *= w, 1;
}
inline bool read(char& s) {
while (s = getchar(), isspace(s))
;
return 1;
}
inline bool read(char* s) {
char ch;
while (ch = getchar(), isspace(ch))
;
if (ch == EOF)
return 0;
while (!isspace(ch))
*s++ = ch, ch = getchar();
*s = '\000';
return 1;
}
template <typename T>
inline void print(T x) {
if (x < 0)
putchar(45), x = -x;
if (x > 9)
print(x / 10);
putchar(x % 10 + 48);
}
inline void print(char x) {
putchar(x);
}
inline void print(char* x) {
while (*x)
putchar(*x++);
}
inline void print(const char* x) {
for (int i = 0; x[i]; i++)
putchar(x[i]);
}
inline bool read(std::string& s) {
s = "";
char ch;
while (ch = getchar(), isspace(ch))
;
if (ch == EOF)
return 0;
while (!isspace(ch))
s += ch, ch = getchar();
return 1;
}
inline void print(std::string x) {
for (int i = 0, n = x.size(); i < n; i++)
putchar(x[i]);
}
inline bool read(bool& b) {
char ch;
while (ch = getchar(), isspace(ch))
;
b = ch ^ 48;
return 1;
}
inline void print(bool b) {
putchar(b + 48);
}
inline bool read(double& x) {
int a = 0, b = 0;
char ch = getchar();
bool f = 0;
while (ch < 48 || ch > 57) {
if (ch == 45)
f = 1;
ch = getchar();
}
while (47 < ch && ch < 58) {
a = (a << 1) + (a << 3) + (ch ^ 48);
ch = getchar();
}
if (ch != 46) {
x = f ? -a : a;
return 1;
}
ch = getchar();
while (47 < ch && ch < 58) {
b = (b << 1) + (b << 3) + (ch ^ 48), ch = getchar();
}
x = b;
while (x > 1)
x /= 10;
x /= 10;
x = f ? -a - x : a + x;
return 1;
}
inline void print(double x) {
if (x < 0) {
putchar(45), x = -x;
}
x = round((long double)x * POW[precision]) / POW[precision],
print((long long)x), putchar(46), x -= (long long)(x);
for (int i = 1; i <= precision; i++)
x *= 10, putchar(x + 48), x -= (int)x;
}
template <typename T, typename... T1>
inline int read(T& a, T1&... other) {
return read(a) + read(other...);
}
template <typename T, typename... T1>
inline void print(T a, T1... other) {
print(a), print(other...);
}
struct Fast_IO {
~Fast_IO() {
fwrite(obuf, p3 - obuf, 1, stdout);
}
} io;
template <typename T>
Fast_IO& operator>>(Fast_IO& io, T& b) {
return read(b), io;
}
template <typename T>
Fast_IO& operator<<(Fast_IO& io, T b) {
return print(b), io;
}
#define cout io
#define cin io
} // namespace fast_IO
using namespace fast_IO;
// #define debug 1
// #define multi_test_ 1
#define endl '\n'
int _test_ = 1;
namespace zqh {
int leaveGame = -1;
int hh = -1;
int movechesser;
bool gameover = false;
int mp[100][100] = {
{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},
};
string ys[15] = {
"red soldier",
"red duck",
"red car",
"red horse",
"red elephant",
"red guard",
"red captain",
"NA",
"blue captain",
"blue guard",
"blue elephant",
"blue horse",
"blue car",
"blue duck",
"blue soldier"
};
void print() {
cout << endl;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9; j++) {
cout << mp[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
bool tzy(int x, int y) {
return (x < 0 && y < 0) || (x > 0 && y > 0);
}
/*
>0 -> Blue
<0 -> Red
no 0
王 1 -1
士 2 -2
象 3 -3
马 4 -4
车 5 -5
鸭 6 -6
兵 7 -7
*/
bool check(int x, int y) {
return (x >= 0 && y >= 0 && x < 10 && y < 9);
}
bool move(int x, int y, int i, int j) {
// cout << x << " " << y << " " << i << " " << j;
leaveGame = 0;
if (!(mp[x][y] && tzy(hh, mp[x][y]) && (!mp[i][j] || !tzy(mp[x][y], mp[i][j])) && check(x, y) &&
check(i, j)))
return false; // 判断目标移动点是否合法
movechesser = mp[x][y];
if (abs(mp[x][y]) == 1) { // 王移动
if (!((abs(x - i) == 1 && y == j) || (x == i && abs(y - j) == 1))) {
return false;
}
} else if (abs(mp[x][y]) == 2) { // 士移动
if (!(abs(x - i) == 1 && abs(y - j) == 1)) {
return false;
}
} else if (abs(mp[x][y]) == 3) { // 象移动
int mx = (x + i) / 2, my = (y + j) / 2;
if (!(abs(x - i) == 2 && abs(y - j) == 2 && !mp[mx][my])) {
return false;
}
} else if (abs(mp[x][y]) == 4) { // 马移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
if (!sx)
continue;
for (int sy = -1; sy <= 1; sy++) {
if (!sy)
continue;
if (check(x + sx, y) && !mp[x + sx][y] &&
(i == x + sx * 2 && j == y + sy)) {
flag = true;
break;
}
if (check(x, y + sy) && !mp[x][y + sy] &&
(i == x + sx && j == y + sy * 2)) {
flag = true;
break;
}
}
}
if (!flag)
return false;
} else if (abs(mp[x][y]) == 5) { // 车移动
if (x != i && y != j)
return false;
bool flag = false;
if (x == i) {
if (y < j) {
bool flag2 = true;
for (int s = y + 1; s <= j - 1; s++) {
if (mp[x][s]) {
flag2 = false;
}
}
if (flag2)
flag = true;
} else {
bool flag2 = true;
for (int s = j + 1; s <= y - 1; s++) {
if (mp[x][s]) {
flag2 = false;
}
}
if (flag2)
flag = true;
}
} else {
if (x < i) {
bool flag2 = true;
for (int s = x + 1; s <= i - 1; s++) {
if (mp[s][y]) {
flag2 = false;
}
}
if (flag2)
flag = true;
} else {
bool flag2 = true;
for (int s = i + 1; s <= x - 1; s++) {
if (mp[s][y]) {
flag2 = false;
}
}
if (flag2)
flag = true;
}
}
if (!flag)
return false;
} else if (abs(mp[x][y]) == 6) { // 鸭移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
if (!sx)
continue;
for (int sy = -1; sy <= 1; sy++) {
if (!sy)
continue;
if (check(x + sx * 2, y + sy) && check(x + sx, y) &&
!mp[x + sx * 2][y + sy] && !mp[x + sx][y] &&
i == x + sx * 3 && j == y + sy * 2) {
flag = true;
break;
}
if (check(x + sx, y + sy * 2) && check(x, y + sy) &&
!mp[x + sx][y + sy * 2] && !mp[x][y + sy] &&
i == x + sx * 2 && j == y + sy * 3) {
flag = true;
break;
}
}
}
if (!flag)
return false;
} else if (abs(mp[x][y]) == 7) { // 兵移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
for (int sy = -1; sy <= 1; sy++) {
if (sx == 0 && sy == 0) continue;
if (check(x + sx, y + sy) && i == x + sx && j == y + sy) {
flag = true;
break;
}
}
}
if (!flag)
return false;
} else return false;
if (mp[i][j] != 0) leaveGame = mp[i][j];
mp[i][j] = mp[x][y];
mp[x][y] = 0;
return true;
}
bool Check() {
//5 4 2 7
int i = -1, j = -1;
for (int s = 0; s < 10; s++) {
for (int t = 0; t < 9; t++) {
if (mp[s][t] == 1) {
i = s, j = t;
break;
}
}
}
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
if (!(mp[x][y] && (!mp[i][j] || !tzy(mp[x][y], mp[i][j])) && check(x, y) &&
check(i, j)))
continue; // 判断目标移动点是否合法
if (abs(mp[x][y]) == 1) { // 王移动
if (!((abs(x - i) == 1 && y == j) || (x == i && abs(y - j) == 1))) {
continue;
}
return true;
} else if (abs(mp[x][y]) == 2) { // 士移动
if (!(abs(x - i) == 1 && abs(y - j) == 1)) {
continue;
}
return true;
} else if (abs(mp[x][y]) == 3) { // 象移动
int mx = (x + i) / 2, my = (y + j) / 2;
if (!(abs(x - i) == 2 && abs(y - j) == 2 && !mp[mx][my])) {
continue;
}
return true;
} else if (abs(mp[x][y]) == 4) { // 马移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
if (!sx)
continue;
for (int sy = -1; sy <= 1; sy++) {
if (!sy)
continue;
if (check(x + sx, y) && !mp[x + sx][y] &&
(i == x + sx * 2 && j == y + sy)) {
flag = true;
break;
}
if (check(x, y + sy) && !mp[x][y + sy] &&
(i == x + sx && j == y + sy * 2)) {
flag = true;
break;
}
}
}
if (flag)
return true;
} else if (abs(mp[x][y]) == 5) { // 车移动
if (x != i && y != j)
continue;
bool flag = false;
if (x == i) {
if (y < j) {
bool flag2 = true;
for (int s = y + 1; s <= j - 1; s++) {
if (mp[x][s]) {
flag2 = false;
}
}
if (flag2)
flag = true;
} else {
bool flag2 = true;
for (int s = j + 1; s <= y - 1; s++) {
if (mp[x][s]) {
flag2 = false;
}
}
if (flag2)
flag = true;
}
} else {
if (x < i) {
bool flag2 = true;
for (int s = x + 1; s <= i - 1; s++) {
if (mp[s][y]) {
flag2 = false;
}
}
if (flag2)
flag = true;
} else {
bool flag2 = true;
for (int s = i + 1; s <= x - 1; s++) {
if (mp[s][y]) {
flag2 = false;
}
}
if (flag2)
flag = true;
}
}
if (flag)
return true;
} else if (abs(mp[x][y]) == 6) { // 鸭移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
if (!sx)
continue;
for (int sy = -1; sy <= 1; sy++) {
if (!sy)
continue;
if (check(x + sx * 2, y + sy) && check(x + sx, y) &&
!mp[x + sx * 2][y + sy] && !mp[x + sx][y] &&
i == x + sx * 3 && j == y + sy * 2) {
flag = true;
break;
}
if (check(x + sx, y + sy * 2) && check(x, y + sy) &&
!mp[x + sx][y + sy * 2] && !mp[x][y + sy] &&
i == x + sx * 2 && j == y + sy * 3) {
flag = true;
break;
}
}
}
if (flag)
return true;
} else if (abs(mp[x][y]) == 7) { // 兵移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
for (int sy = -1; sy <= 1; sy++) {
if (sx == 0 && sy == 0) continue;
if (check(x + sx, y + sy) && i == x + sx && j == y + sy) {
flag = true;
break;
}
}
}
if (flag)
return true;
}
}
}
for (int s = 0; s < 10; s++) {
for (int t = 0; t < 9; t++) {
if (mp[s][t] == -1) {
i = s, j = t;
break;
}
}
}
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
if (!(mp[x][y] && (!mp[i][j] || !tzy(mp[x][y], mp[i][j])) && check(x, y) &&
check(i, j)))
continue; // 判断目标移动点是否合法
if (abs(mp[x][y]) == 1) { // 王移动
if (!((abs(x - i) == 1 && y == j) || (x == i && abs(y - j) == 1))) {
continue;
}
return true;
} else if (abs(mp[x][y]) == 2) { // 士移动
if (!(abs(x - i) == 1 && abs(y - j) == 1)) {
continue;
}
return true;
} else if (abs(mp[x][y]) == 3) { // 象移动
int mx = (x + i) / 2, my = (y + j) / 2;
if (!(abs(x - i) == 2 && abs(y - j) == 2 && !mp[mx][my])) {
continue;
}
return true;
} else if (abs(mp[x][y]) == 4) { // 马移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
if (!sx)
continue;
for (int sy = -1; sy <= 1; sy++) {
if (!sy)
continue;
if (check(x + sx, y) && !mp[x + sx][y] &&
(i == x + sx * 2 && j == y + sy)) {
flag = true;
break;
}
if (check(x, y + sy) && !mp[x][y + sy] &&
(i == x + sx && j == y + sy * 2)) {
flag = true;
break;
}
}
}
if (flag)
return true;
} else if (abs(mp[x][y]) == 5) { // 车移动
if (x != i && y != j)
continue;
bool flag = false;
if (x == i) {
if (y < j) {
bool flag2 = true;
for (int s = y; s <= j; s++) {
if (mp[x][s]) {
flag2 = false;
}
}
if (flag2)
flag = true;
} else {
bool flag2 = true;
for (int s = j; s <= y; s++) {
if (mp[x][s]) {
flag2 = false;
}
}
if (flag2)
flag = true;
}
} else {
if (x < i) {
bool flag2 = true;
for (int s = x; s <= i; s++) {
if (mp[s][y]) {
flag2 = false;
}
}
if (flag2)
flag = true;
} else {
bool flag2 = true;
for (int s = i; s <= x; s++) {
if (mp[s][y]) {
flag2 = false;
}
}
if (flag2)
flag = true;
}
}
if (flag)
return true;
} else if (abs(mp[x][y]) == 6) { // 鸭移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
if (!sx)
continue;
for (int sy = -1; sy <= 1; sy++) {
if (!sy)
continue;
if (check(x + sx * 2, y + sy) && check(x + sx, y) &&
!mp[x + sx * 2][y + sy] && !mp[x + sx][y] &&
i == x + sx * 3 && j == y + sy * 2) {
flag = true;
break;
}
if (check(x + sx, y + sy * 2) && check(x, y + sy) &&
!mp[x + sx][y + sy * 2] && !mp[x][y + sy] &&
i == x + sx * 2 && j == y + sy * 3) {
flag = true;
break;
}
}
}
if (flag)
return true;
} else if (abs(mp[x][y]) == 7) { // 兵移动
bool flag = false;
for (int sx = -1; sx <= 1; sx++) {
for (int sy = -1; sy <= 1; sy++) {
if (sx == 0 && sy == 0) continue;
if (check(x + sx, y + sy) && i == x + sx && j == y + sy) {
flag = true;
break;
}
}
}
if (flag)
return true;
}
}
}
return false;
}
void solve() {
int q;
cin >> q;
while (q--) {
// print();
int x, y, i, j;
cin >> x >> y >> i >> j;
x = 10 - x - 1;
i = 10 - i - 1;
if (gameover) {
cout << "Invalid command\n";
continue;
}
if (!move(x, y, i, j)) {
// print();
cout << "Invalid command\n";
continue;
}
// print();
hh = -hh;
cout << ys[movechesser + 7] << ";" << ys[leaveGame + 7] << ";";
string ans = "";
if (Check()) ans = "yes";
else ans = "no";
if (leaveGame == -1 || leaveGame == 1) {
gameover = true;
}
if (gameover) ans = "no";
cout << ans << ";" << (gameover ? "yes" : "no");
cout << endl;
}
}
void main() {
solve();
}
} // namespace zqh
signed main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
#ifdef debug
freopen("zqh.in", "r", stdin);
freopen("zqh.out", "w", stdout);
#endif
#ifdef multi_test_
cin >> _test_;
#endif
while (_test_--) {
zqh::main();
}
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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;yes;n...
result:
ok 18 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
1000 0 7 2 6 3 8 4 8 3 0 4 0 0 6 8 6 0 3 1 4 6 2 5 3 6 0 5 0 0 4 1 4 9 7 7 6 9 5 8 4 9 5 8 6 7 0 3 2 3 0 2 1 9 2 7 4 5 3 4 2 1 4 2 4 0 1 2 2 6 0 7 1 9 5 8 4 2 6 1 4 2 1 1 2 2 8 8 1 9 8 8 8 6 6 7 7 7 4 9 2 8 8 8 0 2 0 5 2 2 8 6 1 1 7 1 1 0 3 1 2 3 8 3 7 9 0 8 0 0 3 1 2 3 4 2 5 9 6 9 4 6 4 5 5 4 2 7 4...
output:
red horse;NA;no;no Invalid command Invalid command Invalid command Invalid command blue soldier;NA;no;no Invalid command red captain;NA;no;no blue horse;NA;no;no Invalid command Invalid command Invalid command red soldier;NA;no;no blue elephant;NA;no;no Invalid command red captain;NA;no;no Invalid c...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
1000 3 8 4 1 6 2 8 2 0 0 1 5 9 7 7 6 0 7 8 7 9 5 8 6 5 4 1 0 9 7 6 4 9 7 0 3 2 0 3 0 9 3 8 0 2 8 9 2 7 5 7 8 9 5 8 6 9 6 8 2 6 2 6 3 0 7 1 7 9 1 7 2 1 7 0 5 7 0 8 5 9 5 0 4 3 4 4 5 0 6 8 8 6 2 5 1 9 5 8 4 0 1 2 1 0 3 2 4 2 7 8 5 9 8 8 8 0 0 1 0 3 2 7 3 3 0 0 1 0 5 9 4 9 2 7 4 0 1 2 2 9 7 1 0 6 6 6 5...
output:
Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid comm...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
1000 6 4 5 5 9 1 4 5 9 7 5 8 9 4 8 4 0 6 5 1 0 3 5 5 0 3 5 5 9 7 6 2 2 8 9 6 9 5 5 8 0 4 1 4 0 0 5 6 0 7 3 5 2 8 7 8 0 5 6 8 7 8 9 8 9 2 9 3 0 3 1 2 3 2 5 5 0 5 1 6 3 6 5 6 3 2 1 1 0 5 6 7 9 5 3 4 3 0 2 4 3 4 6 3 9 7 8 7 0 6 9 1 6 8 8 4 6 8 6 3 6 0 5 7 2 0 8 7 9 8 4 0 0 7 3 8 0 3 5 2 2 0 1 7 3 2 0 3...
output:
Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command red captain;NA;no;no Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid...
result:
ok 1000 lines