QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292097 | #7179. Fischer's Chess Guessing Game | OAleksa | WA | 7ms | 3912kb | C++14 | 2.0kb | 2023-12-27 18:11:11 | 2023-12-27 18:11:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 960;
vector<char> sv = {'K', 'Q', 'R', 'R', 'B', 'B', 'N', 'N'};
vector<string> perm;
int good(vector<char> ord) {
int x = -1, y = -1, z = -1, b = -1, a = -1;
for (int i = 0;i < 8;i++) {
if (ord[i] == 'K')
z = i;
else if (ord[i] == 'B') {
if (x == -1)
x = i;
else
y = i;
}
else if (ord[i] == 'R') {
if (a == -1)
a = i;
else
b = i;
}
}
return z < b && z > a && x % 2 != y % 2;
};
int diff(string a, string b) {
int r = 0;
for (int x = 0;x < 8;x++)
r += (a[x] == b[x]);
return r;
};
int Ask(string s) {
cout << s << endl;
int r;
cin >> r;
return r;
}
void go() {
vector<string> tr = perm, temp;
while (tr.size() > 1) {
int mn = 1e9;
string bst;
for (auto u : tr) {
vector<int> cnt(10);
for (auto x : tr)
++cnt[diff(u, x)];
int mx = *max_element(cnt.begin(), cnt.end());
if (mx < mn) {
mn = mx;
bst = u;
}
temp.clear();
int r = Ask(bst);
if (r == 8)
return;
for (auto u : tr) {
if (diff(u, bst) == r)
temp.push_back(u);
}
tr = temp;
}
}
Ask(tr[0]);
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
//freopen("newbarn.in", "r", stdin);
//freopen(newbarn.out", "w", stdout);
int tt = 1;
//cin >> tt;
while (tt--) {
vector<int> order(8);
iota(order.begin(), order.end(), 0);
map<string, int> bio;
do {
vector<char> t;
for (int i = 0;i < 8;i++)
t.push_back(sv[order[i]]);
if (good(t)) {
string s;
for (auto x : t)
s += x;
if (bio[s])
continue;
bio[s] = 1;
perm.push_back(s);
}
} while (next_permutation(order.begin(), order.end()));
assert(perm.size() == N);
while (true) {
string s;
cin >> s;
if (s == "GAME") {
cin >> s;
go();
}
else
break;
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 3912kb
input:
GAME 1 3 0 3 3 3 3
output:
QRKRBBNN QRKNRNBB RKBRNBQN RQNKBBRN RNQKBBRN RNQKBBRN RNQKBBRN
result:
wrong answer (i) too many guesses in game 1, pos = @