QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708868 | #7179. Fischer's Chess Guessing Game | thieunguyenhuy | TL | 56ms | 3880kb | C++14 | 3.8kb | 2024-11-04 09:00:43 | 2024-11-04 09:00:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define popcount(n) (__builtin_popcountll((n)))
#define clz(n) (__builtin_clzll((n)))
#define ctz(n) (__builtin_ctzll((n)))
#define lg(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))
#define Int __int128
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;
template <class T1, class T2>
bool maximize(T1 &x, T2 y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T>
void remove_duplicate(vector<T> &ve) {
sort (ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T> T random(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
template <class T> T random(T r) {
return rng() % r;
}
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
vector<string> states;
bool is960(string position) {
vector<int> where(5, -1);
for (int i = 0; i < 8; ++i) {
if (position[i] == 'R') {
if (where[0] == -1) where[0] = i;
else where[1] = i;
}
if (position[i] == 'B') {
if (where[2] == -1) where[2] = i;
else where[3] = i;
}
if (position[i] == 'K') where[4] = i;
}
if (where[0] > where[4] || where[1] < where[4]) return false;
if (where[2] % 2 == where[3] % 2) return false;
return true;
}
void generate() {
string position = "RRNNBBKQ"; states.clear();
sort (position.begin(), position.end());
do {
if (is960(position)) states.emplace_back(position);
} while (next_permutation(position.begin(), position.end()));
remove_duplicate(states);
cerr << "There are " << states.size() << " positions\n";
}
int count(const string &s, const string &t) {
int ans = 0;
for (int i = 0; i < 8; ++i) if (s[i] == t[i]) {
++ans;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
generate();
string input;
while (cin >> input) {
if (input == "END") break;
int testId; cin >> testId;
vector<string> candidates = states;
while (true) {
int mi = inf; string best;
for (auto candidate : candidates) {
int ma = -1;
for (int correct = 0; correct <= 8; ++correct) {
int sz = 0;
for (auto other : candidates) if (count(candidate, other) == correct) {
++sz;
}
maximize(ma, sz);
}
if (minimize(mi, ma)) best = candidate;
}
cout << best << endl;
int correct; cin >> correct;
if (correct == 8) break;
vector<string> newCandidates;
for (auto other : candidates) if (count(best, other) == correct) {
newCandidates.emplace_back(other);
}
candidates = newCandidates;
}
}
cerr << '\n'; return 0;
}
详细
Test #1:
score: 100
Accepted
time: 56ms
memory: 3880kb
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...