QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#318955 | #7179. Fischer's Chess Guessing Game | PhanDinhKhoi# | RE | 0ms | 0kb | C++20 | 3.7kb | 2024-02-01 12:08:29 | 2024-02-01 12:08:29 |
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz
#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
template<class X, class Y>
bool minimize(X &x, const Y &y) {
if (x > y)
{
x = y;
return true;
}
return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
if (x < y)
{
x = y;
return true;
}
return false;
}
const int MOD = 1e9 + 7; //998244353
template<class X, class Y>
void add(X &x, const Y &y) {
x = (x + y);
if(x >= MOD) x -= MOD;
}
template<class X, class Y>
void sub(X &x, const Y &y) {
x = (x - y);
if(x < 0) x += MOD;
}
/* Author : Le Ngoc Bao Anh, DUT, Da Nang */
const ll INF = 1e9;
const int N = 1000 + 10;
int B[N];
string root2[N];
int f[N][N];
void BaoJiaoPisu() {
string a = "RQKBBNRN";
vector<string> cand;
sort(all(a));
int sz = 8;
do {
bool ok = true;
int G = 0, cnt = 0;
for(int i = 0; i < 8; i++) {
cnt += (a[i] == 'R');
if(a[i] == 'K') ok &= (cnt == 1);
if(a[i] == 'B') G += (i & 1);
}
ok &= (G == 1);
if(ok) cand.pb(a);
} while(next_permutation(all(a)));
auto cnt = [&](string a, string b) -> int {
int ans = 0;
for(int i = 0; i < 8; i++) {
ans += (a[i] == b[i]);
}
return ans;
};
for(int i = 0; i < 960; i++) {
for(int j = 0; j < 960; j++) {
f[i][j] = cnt(cand[i], cand[j]);
}
}
auto get_opt = [&](vector<int> curr) -> int {
int ans = 0;
int opt = INF;
for(int i = 0; i < 960; i++) {
for(int j = 0; j <= 8; j++) B[j] = 0;
int T = 0;
for(int j = 0; j < curr.size(); j++) {
++B[f[i][curr[j]]];
}
for(int j = 0; j <= 8; j++) maximize(T, B[j]);
if(minimize(opt, T)) ans = i;
}
return ans;
};
vector<int> curr;
for(int i = 0; i < 960; i++) curr.pb(i);
int root = get_opt(curr);
root2[0] = "RKNNRQBB";
root2[1] = "BRNNKBQR";
root2[2] = "RNBBQKRN";
root2[3] = "RBBNQKRN";
root2[4] = "BNRBNKRQ";
root2[5] = "BQRBNNKR";
root2[6] = "BNNBRKRQ";
root2[7] = "BBNNQRKR";
while(true) {
string s; cin >> s;
if(s == "END") break;
int x; cin >> x;
vector<int> curr;
for(int i = 0; i < 960; i++) curr.pb(i);
int cnt = 0;
int last = 0;
while(true) {
cnt++;
assert(cnt <= 6);
int ask;
if(cnt == 1) ask = root;
if(cnt > 1) ask = get_opt(curr);
cout << cand[ask] << endl;
int x; cin >> x;
last = x;
if(x == 8) break;
vector<int> ncurr;
for(auto p : curr) {
if(f[p][ask] == x) ncurr.pb(p);
}
curr = ncurr;
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
//online
#endif
int tc = 1, ddd = 0;
// cin >> tc;
while(tc--) {
//ddd++;
//cout << "Case #" << ddd << ": ";
BaoJiaoPisu();
}
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
GAME 1 1 0 2 4 0 0
output:
NRBBNKQR BRNNKBQR NBRKNQBR QBRKBRNN BBNNQRKR BBNNQRKR