QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224649 | #7179. Fischer's Chess Guessing Game | sofija6 | TL | 278ms | 77076kb | C++17 | 2.3kb | 2023-10-23 07:06:50 | 2023-10-23 07:06:51 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
set<string> v;
set<pair<string,ll> > S;
void Create(string s,ll b,ll p,ll k,ll n,ll q,ll r)
{
if ((ll)s.size()==8)
{
v.insert(s);
return;
}
string c=s;
if (!b || (b==1 && p!=s.size()%2))
{
c+='B';
Create(c,b+1,s.size()%2,k,n,q,r);
c=s;
}
if (!k && r==1)
{
c+='K';
Create(c,b,p,k+1,n,q,r);
c=s;
}
if (n!=2)
{
c+='N';
Create(c,b,p,k,n+1,q,r);
c=s;
}
if (!q)
{
c+='Q';
Create(c,b,p,k,n,q+1,r);
c=s;
}
if (!r || (r==1 && k==1))
{
c+='R';
Create(c,b,p,k,n,q,r+1);
}
return;
}
map<string,set<string> > c[10];
set<string> w;
bool Check(string x)
{
for (auto i : S)
{
ll diff=0;
for (ll j=0;j<8;j++)
diff+=(i.first[j]!=x[j]);
if (diff>i.second || !diff)
return false;
}
return true;
}
string Get_Min()
{
ll maxx=LLONG_MAX;
string ans;
for (auto i : w)
{
ll cur=0;
for (ll j=0;j<9;j++)
{
ll num=0;
for (auto l : c[j][i])
{
if (Check(l))
num++;
}
cur=max(cur,num);
}
if (cur<maxx && Check(i))
{
maxx=cur;
ans=i;
}
}
return ans;
}
int main()
{
string s="";
Create(s,0,0,0,0,0,0);
for (auto i : v)
{
for (auto j : v)
{
ll cnt=0;
for (ll p=0;p<8;p++)
cnt+=(i[p]!=j[p]);
c[cnt][i].insert(j);
}
}
string x="";
ll n,a;
while (true)
{
if (x=="")
cin >> x;
cin >> n;
S.clear();
w=v;
s=Get_Min();
while (true)
{
cout << s << "\n";
cin >> a;
a=8-a;
if (!a)
{
cin >> x;
if (x=="END")
return 0;
break;
}
w=c[a][s];
S.insert({s,a});
s=Get_Min();
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 278ms
memory: 77076kb
input:
GAME 1 1 2 4 3 1 8 END
output:
NRBBNKQR RNBQKBRN RKBBQNNR RKBQNRNB RBBKNNQR 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 4 3 1 8 GAME 2 2 2 3 4 3 8 GAME 3 1 1 1 5 4 3
output:
NRBBNKQR RNBQKBRN RKBBQNNR RKBQNRNB RBBKNNQR RKRBBQNN NRBBNKQR RBBNQNKR RNBBKQRN RKNBBQNR RKBBNRNQ RKRBBNQN NRBBNKQR RNBQKBRN NQRKNBBR RKBBQNNR RKQBNNBR RQBBNKNR