QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#686494 | #6394. Turn on the Light | libantian# | TL | 0ms | 0kb | C++23 | 601b | 2024-10-29 13:50:17 | 2024-10-29 13:50:18 |
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define all(_a) _a.begin(), _a.end()
void solve(int l,int r,int y){
int x;
printf("? %d\n",r);
scanf("%d",&x);
if (x==y) {printf("! %d\n",r); exit(0);}
y=x;
int mid=l+r>>1;
printf("? %d\n",mid);
scanf("%d",&x);
if (x==y) {printf("! %d\n",mid); exit(0);}
if (x==y+1) solve(l,mid-1,x); else solve(mid+1,r,x);
}
signed main(){
int n;
scanf("%d",&n);
solve(1,n,0);
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3