QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227884#7179. Fischer's Chess Guessing Gamesofija6TL 1ms3876kbC++172.4kb2023-10-28 02:39:312023-10-28 02:39:31

Judging History

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

  • [2023-10-28 02:39:31]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3876kb
  • [2023-10-28 02:39:31]
  • 提交

answer

#include <bits/stdc++.h>
#define ll int
using namespace std;
vector<string> v,startt[10],d[10],cur;
string ans;
string Get_Min()
{
    ll maxx=INT_MAX;
    string sol;
    for (string i : cur)
    {
        if (i==ans)
            continue;
        ll cnt[10]={0},m=0;
        for (string j : cur)
        {
            if (j==ans)
                continue;
            ll num=0;
            for (ll l=0;l<8;l++)
                num+=(i[l]!=j[l]);
            cnt[num]++;
            m=max(m,cnt[num]);
        }
        if (m<maxx)
        {
            maxx=m;
            sol=i;
        }
    }
    for (ll i=0;i<9;i++)
        d[i].clear();
    for (string i : cur)
    {
        ll num=0;
        for (ll l=0;l<8;l++)
            num+=(i[l]!=sol[l]);
        d[num].push_back(i);
    }
    return sol;
}
void Solve(ll a)
{
    cur=d[a];
    ans=Get_Min();
}
ll b,p,k,n,q,r,prevv;
string s;
void Create()
{
    if ((ll)s.size()==8)
    {
        v.push_back(s);
        return;
    }
    if (!b || (b==1 && p!=s.size()%2))
    {
        b++;
        prevv=p;
        p=s.size()%2;
        s+='B';
        Create();
        p=prevv;
        b--;
        s.pop_back();
    }
    if (!k && r==1)
    {
        s+='K';
        k++;
        Create();
        k--;
        s.pop_back();
    }
    if (n!=2)
    {
        s+='N';
        n++;
        Create();
        n--;
        s.pop_back();
    }
    if (!q)
    {
        s+='Q';
        q++;
        Create();
        q--;
        s.pop_back();
    }
    if (!r || (r==1 && k==1))
    {
        s+='R';
        r++;
        Create();
        r--;
        s.pop_back();
    }
    return;
}
int main()
{
    string x="",ans0="NRBBNKQR";
    Create();
    ll a;
    for (auto i : v)
    {
        ll cnt=0;
        for (ll j=0;j<8;j++)
            cnt+=(ans0[j]!=i[j]);
        startt[cnt].push_back(i);
    }
    while (true)
    {
        if (x=="")
            cin >> x;
        cin >> n;
        ans=ans0;
        for (ll i=0;i<9;i++)
            d[i]=startt[i];
        while (true)
        {
            cout << ans << "\n";
            cin >> a;
            a=8-a;
            if (!a)
            {
                cin >> x;
                if (x=="END")
                    return 0;
                break;
            }
            Solve(a);
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3876kb

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...

result: