QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628302#7179. Fischer's Chess Guessing Gameucup-team3519#TL 38ms3780kbC++172.2kb2024-10-10 19:33:082024-10-10 19:33:09

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 19:33:09]
  • 评测
  • 测评结果:TL
  • 用时:38ms
  • 内存:3780kb
  • [2024-10-10 19:33:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
typedef double db;
typedef long long LL;

typedef pair<int, int> pi;
#define fi first
#define se second
#define all0(x) (x).begin(), (x).end()

mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());

V<string> pos;

int same_cnt(string a, string b) {
    int cnt = 0;
    for(int i = 0; i < a.size(); i++) if(a[i] == b[i]) cnt++;
    return cnt;
}

bool hav(V<string> vs, string s) {
    for(auto x : vs) if(x == s) return 1;
    return 0;
}

void solve() {
    // string set_an
    V<string> now = pos;
    int cnt = 0;
    while(now.size() > 1) {

        cnt++;
        assert(cnt <= 5);
        int mn = 10000;
        string use;
        for(auto s : pos) {
            V<int> hav(9);
            for(auto t : now) {
                hav[same_cnt(s, t)]++;
            }
            int mx = *max_element(all0(hav));
            if(mx < mn) {
                mn = mx, use = s;
            }
        }

        cout << use << endl;
        int t; cin >> t;
        if(t == 8) {
            return;
        }
        V<string> n_now;
        for(auto s : now) {
            if(same_cnt(use, s) == t) n_now.pb(s);
        }
        swap(now, n_now);
    }
    cout << now[0] << endl;
    int t; cin >> t;
    assert(t == 8);
}

bool king_in_rock(string s) {
    int f_r = -1, l_r, k;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'K') k = i;
        if(f_r == -1 && s[i] == 'R') f_r = i;
        if(s[i] == 'R') l_r = i;
    }
    if(k > f_r && k < l_r) return 1;
    return 0;
}
bool bishop_in_dif(string s) {
    int hav0 = 0, hav1 = 0;

    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'B') {
            if(i & 1) hav1++;
            else hav0++;
        }
    }

    if(hav1 == 1) return 1;
    return 0;
}

void initial() {
    string s = "NNKQBBRR";
    sort(all0(s));
    do{
        if(bishop_in_dif(s) && king_in_rock(s)) pos.pb(s);
    }while(next_permutation(all0(s)));
}

int main() {

    initial();

    string s; cin >> s;
    while(s != "END") {
        int t; cin >> t;
        solve();
        // cout << "solve end" << endl;
        cin >> s;
    }
}   

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 38ms
memory: 3780kb

input:

GAME 1
1
0
2
4
8
END

output:

NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
RKRBBQNN

result:

ok (c) correct after 1 tests, max moves 5 (1 test case)

Test #2:

score: -100
Time Limit Exceeded

input:

GAME 1
1
0
2
4
8
GAME 2
2
3
3
1
1
8
GAME 3
1
0
1
2
8
GAME 4
1
0
2
2
1
8
GAME 5
2
3
4
2
8
GAME 6
2
2
4
0
0
8
GAME 7
0
2
3
2
0
8
GAME 8
1
3
3
0
8
GAME 9
0
3
3
0
8
GAME 10
0
3
3
1
8
GAME 11
0
5
1
0
8
GAME 12
1
2
2
1
0
8
GAME 13
1
1
5
1
8
GAME 14
0
4
4
3
8
GAME 15
1
2
1
2
1
8
GAME 16
1
0
3
1
0
8
GAME 17...

output:

NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
RKRBBQNN
NRBBNKQR
RNBBQKRN
RQKBNNBR
BBRNNQKR
BBNNRKQR
RKRBBNQN
NRBBNKQR
BRNNKBQR
NBRKNQBR
BNRKQRNB
RKRBBNNQ
NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
BBNNQRKR
RKRBQNBN
NRBBNKQR
RNBBQKRN
RQKBNNBR
QNRBBKNR
RKRBNQBN
NRBBNKQR
RNBBQKRN
QNRBKNBR
BBNNQRKR
BBNNRKQR
RKRBNNBQ
NRB...

result: