QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613174 | #6394. Turn on the Light | liaoyingyu | TL | 0ms | 0kb | C++20 | 820b | 2024-10-05 13:41:08 | 2024-10-05 13:41:13 |
answer
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
const int mod=1e9+7;
const int N=200000+10;
using namespace std;//初始化
typedef pair <int, int> pi;
int n;
int digui(int l,int r,int zhi){
int mid=(l+r)/2;
cout<<"? "<<mid<<endl;
int now,noww;
cin>>now;
if(now==zhi){
return mid;
}
cout<<"? "<<l<<endl;
cin>>noww;
if(now==noww){
return l;
}
else{
if(noww>now){
digui(mid+1,r,noww);
}
else if(noww<now){
digui(l+1,mid,noww);
}
}
}
void solve(){
cin>>n;
int nnn=digui(1,n,0);
cout<<"! "<<nnn<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
cout << fixed << setprecision(12);//小数保留位数
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
3 1 2 2 2 2
output:
? 2 ? 1 ? 3 ? 2 ? 2