QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574027 | #6394. Turn on the Light | hhhhyf | WA | 1ms | 3716kb | C++20 | 898b | 2024-09-18 20:36:21 | 2024-09-18 20:36:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int tag;
void solve(int l,int r,int lst)
{
if(tag==1)
{
return;
}
int mid,x,y;
mid=(l+r + 1)>>1;
if(l==r)
{
tag=1;
cout<<"! "<<r << endl;
exit(0);
}
cout<<"? "<<mid<< endl;
cin>>x;
if(x==lst)
{
tag=1;
cout<<"! "<<mid << endl;
// cout.flush();
exit(0);
}
cout<<"? "<<r<< endl;
cin>>y;
if(y==x)
{
tag=1;
cout<<"! "<<r << endl;
exit(0);
}
if(x < y)
{
solve(l,mid-1,y);
}
else
{
solve(mid+1,r-1,y);
}
return;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int n;
cin>>n;
tag=0;
solve(1,n,0);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3716kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3640kb
input:
10 1 2 3 4 5 5
output:
? 6 ? 10 ? 3 ? 5 ? 2 ? 2 ! 2
result:
wrong answer Wrong favorite light!