QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225684 | #7179. Fischer's Chess Guessing Game | sofija6 | TL | 0ms | 0kb | C++17 | 2.3kb | 2023-10-24 23:02:22 | 2023-10-24 23:02:23 |
answer
#include <bits/stdc++.h>
#define ll int
using namespace std;
vector<string> v;
vector<pair<string,ll> > S;
set<string> cor;
string Get_Min()
{
ll maxx=INT_MAX;
string ans;
set<string> ss;
for (auto j : cor)
{
for (auto i : S)
{
ll d=0;
for (ll p=0;p<8;p++)
d+=(i.first[p]!=j[p]);
if (d!=i.second)
ss.insert(j);
}
}
for (auto i : ss)
cor.erase(i);
for (auto i : cor)
{
ll cnt[10]={0},cur=0;
for (auto l : cor)
{
if (i==l)
continue;
ll diff=0;
for (ll p=0;p<8;p++)
diff+=(i[p]!=l[p]);
cnt[diff]++;
cur=max(cur,cnt[diff]);
}
if (cur<maxx)
{
ans=i;
maxx=cur;
}
}
return ans;
}
ll b,p,k,n,q,r;
void Create(string s)
{
if ((ll)s.size()==8)
{
v.push_back(s);
return;
}
string c=s;
if (!b || (b==1 && p!=s.size()%2))
{
c+='B';
b++;
p=s.size()%2;
Create(c);
b--;
c=s;
}
if (!k && r==1)
{
c+='K';
k++;
Create(c);
k--;
c=s;
}
if (n!=2)
{
c+='N';
n++;
Create(c);
n--;
c=s;
}
if (!q)
{
c+='Q';
q++;
Create(c);
q--;
c=s;
}
if (!r || (r==1 && k==1))
{
c+='R';
r++;
Create(c);
r--;
}
return;
}
int main()
{
string s="";
Create(s);
string x="";
ll N,a;
while (true)
{
if (x=="")
cin >> x;
cin >> N;
S.clear();
for (auto i : v)
cor.insert(i);
s=Get_Min();
while (true)
{
cout << s << "\n";
cin >> a;
a=8-a;
if (!a)
{
cin >> x;
if (x=="END")
return 0;
break;
}
S.push_back({s,a});
s=Get_Min();
}
}
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
GAME 1
output:
RQKBNNRB