题解:CF2013C Password Cracking / [SNOW] - 76
fish_love_cat · · 题解
考虑直接大力向后拼接。
有多个匹配的串不用管,能拼则拼,等到无论向后拼什么都无法匹配的时候那么原来的串的位置就确定下来了,此时一定是目标序列的一段后缀。
于是我们改向前拼接,此时可以优化尝试方式,因为串的位置已经固定所以向前只需要一次尝试就可以确定是什么东西。
如果长度已经符合要求那么直接退出即可。
限制是很松的。
#include<bits/stdc++.h>
using namespace std;
bool ask(string s){
cout<<"? "<<s<<endl;
bool x;
cin>>x;
return x;
}
void solve(){
int n;
cin>>n;
string ans;
if(ask("0"))ans="0";
else ans="1";
bool qwq=1;
while(1){
if(ans.size()==n)break;
if(qwq){
bool q0=ask(ans+"0");
bool q1=ask(ans+"1");
if(q0)ans+="0";
else if(q1)ans+="1";
else qwq=0;
}else{
bool q0=ask("0"+ans);
if(q0)ans="0"+ans;
else ans="1"+ans;
}
}
cout<<"! "<<ans<<endl;
}
int main(){
int t;
cin>>t;
while(t--)solve();
return 0;
}
//「骗人。」
// #76