QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500405 | #7179. Fischer's Chess Guessing Game | ucup-team1766 | TL | 3ms | 3780kb | C++17 | 2.2kb | 2024-08-01 11:17:51 | 2024-08-01 11:17:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<string> boards;
bool valid(string &board) {
vector<int> b_inds;
vector<int> r_inds;
int k_ind;
for (int i = 0; i < board.size(); i++) {
if (board[i] == 'B') {
b_inds.push_back(i);
} else if (board[i] == 'K') {
k_ind = i;
} else if (board[i] == 'R') {
r_inds.push_back(i);
}
}
return ((b_inds[0] % 2) != (b_inds[1] % 2) && k_ind > r_inds[0] && k_ind < r_inds[1]);
}
int match_cnt(string &a, string &b) {
int ret = 0;
for (int i = 0; i < a.size(); i++) {
ret += (a[i] == b[i]);
}
return ret;
}
void solve() {
vector<string> left(boards.begin(), boards.end());
while (true) {
// cnts[i][j] = # of boards left matching j characters with board i
vector<vector<int>> cnts(left.size(), vector<int>(9));
vector<int> max_cnt(left.size());
int min_max = 0;
for (int i = 0; i < left.size(); i++) {
for (int j = 0; j < left.size(); j++) {
cnts[i][match_cnt(left[i], left[j])]++;
}
for (int j = 0; j < 9; j++) {
max_cnt[i] = max(max_cnt[i], cnts[i][j]);
}
if (max_cnt[i] < max_cnt[min_max]) {
min_max = i;
}
}
cout << left[min_max] << endl;
int match;
cin >> match;
if (match == 8) {
break;
}
vector<string> next_left;
for (string board : left) {
if (match_cnt(left[min_max], board) == match) {
next_left.push_back(board);
}
}
left = next_left;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string cur_board = "BBKNNQRR";
do {
if (valid(cur_board)) {
boards.push_back(cur_board);
}
} while (next_permutation(cur_board.begin(), cur_board.end()));
string status;
int game;
cin >> status >> game;
while (true) {
solve();
cin >> status;
if (status == "END") {
break;
}
cin >> game;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3780kb
input:
GAME 1 1 2 2 1 2 8 END
output:
NRBBNKQR BNRKQBNR RNBQKRNB BRNQKBRN QNRNBKRB RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 6 (1 test case)
Test #2:
score: -100
Time Limit Exceeded
input:
GAME 1 1 2 2 1 2 8 GAME 2 2 1 0 1 2 8 GAME 3 1 2 2 0 3 8 GAME 4 1 2 1 1 3 8 GAME 5 2 2 0 3 0 8 GAME 6 2 1 2 1 3 8 GAME 7 0 2 3 4 3 8 GAME 8 1 2 1 0 3 8 GAME 9 0 3 1 2 8 GAME 10 0 3 3 3 8 GAME 11 0 5 3 2 8 GAME 12 1 1 1 4 8 GAME 13 1 2 2 3 4 8 GAME 14 0 4 3 4 8 GAME 15 1 2 1 0 1 8 GAME 16 1 1 3 2 2 8...
output:
NRBBNKQR BNRKQBNR RNBQKRNB BRNQKBRN QNRNBKRB RKRBBQNN NRBBNKQR RBBNKQNR QRKNNRBB NBNRBKRQ BQNBRNKR RKRBBNQN NRBBNKQR BNRKQBNR RNBQKRNB BRNQKBRN RBKNBQNR RKRBBNNQ NRBBNKQR BNRKQBNR RNBQKRNB BBNQRNKR QBRKNRBN RKRBQNBN NRBBNKQR RBBNKQNR NBNQBRKR BRKBRQNN QRBKRNNB RKRBNQBN NRBBNKQR RBBNKQNR QRKNNRBB NRK...