题解:CF2280B Secret String Patterns
xiaozekai11 · · 题解
题意简述
有一个隐藏的
最后问这个隐藏的字符串是否存在一个
思路
其实根本不用
首先正难则反,考虑什么情况下没有。很明显,只有三种情况:
- 全是
1 ; - 全是
0 ; - 前面全是
1 ,后面全是0 。
否则,就一定存在了。
那么就简单了。首先询问
参考代码
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll T,n,x,y;
int main(){
// 交互题不能关闭同步流
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
cin>>n;
cout<<"? 1 "<<n<<endl;
cin>>x;
if(!x||x==n){
cout<<"! NO"<<endl;// 全是 0 或全是 1
continue;
}
cout<<"? 1 "<<x<<endl;
cin>>y;
if(x==y)cout<<"! NO"<<endl;
else cout<<"! YES"<<endl;
}
return 0;
}