QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224124#7179. Fischer's Chess Guessing GameMihailo_JancevicTL 0ms0kbC++142.0kb2023-10-23 00:01:172023-10-23 00:01:18

Judging History

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

  • [2023-10-23 00:01:18]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-23 00:01:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

vector<string> sol, sol1;
string s;
int dif[1000][10], t, x, mindif, j;

void gen(string s, int r, int b, int n, int k, int q) {
    if(s.size()==8) {
        sol.push_back(s);
        return;
    }
    if(r==1&&k==0) gen(s+"K", r, b, n, k+1, q);
    if(r==0||(k==1&&r==1)) gen(s+"R", r+1, b, n, k, q);
    if(n<2) gen(s+"N", r, b, n+1, k, q);
    if(b==0) gen(s+"B", r, s.size()+1, n, k, q);
    if(b<10&&b>0&&(b+s.size()+1)%2) gen(s+"B", r, 100, n, k, q);
    if(q==0) gen(s+"Q", r, b, n, k, q+1);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    while(true) {
        cin>>s;
        if(s[0]=='E') break;
        cin>>s;
        sol.clear();
        gen("", 0, 0, 0, 0, 0);
        while(sol.size()>1) {
            mindif=1204374;
            for(int i=0; i<sol.size(); i++) {
                for(int j=0; j<9; j++) dif[i][j]=0;
                for(int j=0; j<sol.size(); j++) {
                    t=0;
                    for(int k=0; k<8; k++) {
                        if(sol[i][k]==sol[j][k]) t++;
                    }
                    dif[i][t]++;
                }
                for(int k=1; k<9; k++) {
                    dif[i][0]=max(dif[i][0], dif[i][k]);
                }
                mindif=min(mindif, dif[i][0]);
            }
            for(int i=0; i<sol.size(); i++) {
                if(dif[i][0]==mindif) {
                    cout<<sol[i]<<endl;
                    cin>>x;
                    j=i;
                    break;
                }
            }
            if(x==8) continue;
            sol1.clear();
            for(int i=0; i<sol.size(); i++) {
                t=0;
                for(int k=0; k<8; k++) {
                    if(sol[i][k]==sol[j][k]) t++;
                }
                if(t==x) sol1.push_back(sol[i]);
            }
            sol=sol1;
        }
        cout<<sol[0]<<endl;
        cin>>x;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

GAME 1
3
1
5
8
END

output:

RQKNBBRN
NRBKQBRN
RKNBBRQN
RKRBBQNN
RKRBBQNN
RKRBBQNN

result: