题意:猜密码.初始有个长度至多128的字符串,字符集大小为62,然后你需要在850次询问内找到答案.每次告诉你两个串的莱文斯坦距离
首先,我们用62次询问找出每个字符的出现次数.
然后,我们用归并排序的思想合并两个字符集的对应答案.
#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()
#define mk make_pair
#define pi pair<int,int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int L=133,A=66;
template<class o>void qr(o&x) {
char c=gc;int f=1;x=0;
while(!isdigit(c)){if(c=='-')f=-1;c=gc;}
while(isdigit(c))x=x*10+c-'0',c=gc;
x*=f;
}
template<class o>void qw(o x) {
if(x/10)qw(x/10);
putchar(x%10+'0');
}
template<class o> void pr1(o x) {
if(x<0)x=-x,putchar('-');
qw(x); putchar(' ');
}
template<class o>void pr2(o x) {
if(x<0)x=-x,putchar('-');
qw(x);puts("");
}
char s[A][L],ch[A],t[L];
int len[A],n,cnt;
int ask(char *s,int l) {
s[l+1]=0; printf("? "); puts(s+1); fflush(stdout);
int x; qr(x); return x;
}
void solve(int l,int r) {
if(l==r) return ;
int mid=(l+r)>>1;
solve(l,mid); if(len[l]^n) solve(mid+1,r);
int a=len[l],b=len[++mid],i=1,j=1,x;
len[l]=0;
while(i<=a&&j<=b) {
t[++len[l]]=s[l][i];
x=len[l]; for(int k=j;k<=b;k++) t[++x]=s[mid][k];
if(n-ask(t,x)==x) i++;
else t[len[l]]=s[mid][j++];
}
while(i<=a) t[++len[l]]=s[l][i++];
while(j<=b) t[++len[l]]=s[mid][j++];
memcpy(s[l],t,sizeof t);
}
int main() {
for(int i=0;i<26;i++) ch[++cnt]='a'+i,ch[++cnt]='A'+i;
for(int i=0;i<=9;i++) ch[++cnt]='0'+i;
for(int i=1;i<=cnt;i++) {
for(int j=1;j<=128;j++) t[j]=ch[i];
len[i]=128-ask(t,128);
n+=len[i];
for(int j=1;j<=len[i];j++) s[i][j]=ch[i];
}
solve(1,A); s[1][n+1]=0; printf("! %s\n",s[1]+1);
return 0;
}