QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#392890 | #2409. 猜词 | marher | 100 ✓ | 6305ms | 4456kb | C++14 | 2.6kb | 2024-04-17 21:50:17 | 2024-04-17 21:50:18 |
Judging History
answer
#include "word.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=8900;
string s[N],las;
int n;
vector<int>cur;
int w(char c)
{
return 1<<(c-'a');
}
void clear(char c)
{
las="";cur.clear();
for(int i=0;i<n;i++)if(s[i][0]==c)cur.push_back(i);
}
int get(int A,int B)
{
int ans=0;
string a=s[A],b=s[B];
for(int i=0,mi=1;i<5;i++,mi*=3)
{
if(a[i]==b[i])
{
ans+=2*mi;
continue;
}
int f=0;
for(int j=0;j<5;j++)if(a[j]!=b[j]&&a[j]==b[i])f=1;
ans+=f*mi;
}
return ans;
}
void solve(bool*g,bool*c)
{
vector<int>p;
for(auto x:cur)
{
int f=0;
for(int i=0;i<5;i++)
{
if(las[i]==s[x][i])
{
if(!g[i]){f=1;break;}
continue;
}
if(g[i]){f=1;break;}
int ff=0;
for(int j=0;j<5;j++)if(s[x][j]==las[i]&&s[x][j]!=las[j])ff=1;
if(c[i]!=ff){f=1;break;}
}
if(!f)p.push_back(x);
}
swap(p,cur);
}
void init(int num_scramble, const char *scramble)
{
int pos=0;n=num_scramble;
for(int i=0;i<num_scramble;i++)
for(int j=1;j<=5;j++)s[i]=s[i]+scramble[pos++];
}
double getE(int x,int re)
{
double ans=0;
int mp[256];memset(mp,0,sizeof mp);
for(auto y:cur)mp[get(y,x)]++;
for(int i=0;i<250;i++)if(mp[i])
{
double p=1.0*mp[i]/cur.size();
ans-=p*log2(p);
}
if(re==4)ans+=0.1*mp[242];
else if(re<=3)ans+=1.0*mp[242]/cur.size();
return ans;
}
string solve(int re)
{
double mx=-10000000;int now=cur[0];
for(int i=0;i<n;i++)
{
double g=getE(i,re);
if(g>mx)mx=g,now=i;
}
return s[now];
}
char ss[7];
string pre[50]={"slier","lares","lares","tores","tarns","arles","lares","lares","snare","ousel","ranis","nares","tares","aides","tries","lares","raise","aides","plate","nares","snare","riles","nares","cones","kanes","aeons"};
const char *guess(int num_testcase, int remaining_guesses, char initial_letter, bool *gold, bool *silver)
{
if(remaining_guesses==5)
{
clear(initial_letter);
las=pre[initial_letter-'a'];
}
else
{
solve(gold,silver);
if(cur.size()<=2)las=s[cur[0]];
else las=solve(remaining_guesses);
}
for(int i=0;i<5;i++)ss[i]=las[i];
// cout<<"\""<<las<<"\",";
return ss;
}
// bool sd[N],fd[N];
// int main()
// {
// init(8869,SCRAMBLE);
// for(int i='a';i<='z';i++)guess(1,5,(char)i,sd,fd);
// }
詳細信息
Test #1:
score: 100
Accepted
time: 6305ms
memory: 4456kb
input:
1000 258971 aahedaaliiaarghabacaabaciabackabaftabakaabampabaseabashabateabayaabbasabbesabbeyabbotabeamabeleabetsabhorabideabledablerablesabmhoabodeabohmaboilabomaaboonabortaboutaboveabrisabuseabutsabuzzabyesabysmabyssacariacerbacetaachedachesachooacidsacidyacingaciniackeeacmesacmicacnedacnesacockaco...
output:
100.000
result:
points 1.0 finished