QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#371724 | #6394. Turn on the Light | acansaidong# | WA | 1ms | 3848kb | C++23 | 687b | 2024-03-30 15:12:37 | 2024-03-30 15:12:38 |
Judging History
answer
#include <bits/stdc++.h>
#include <sstream>
//#define int long long
#define endl '\n'
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
signed main() {
int n,x,y;
cin>>n;
int a=0,aa=0;
int l=1,r=n;
while(l<=r) {
int x,y;
printf("? %d\n",l);
cin>>x;
if(x==a)
{
printf("! %d\n",l);return 0;
}
printf("? %d\n",(l+r)/2);
cin>>y;
if(y==x)
{
printf("! %d\n",(l+r)/2);return 0;
}
else if(x<y)
{
l=(l+r)/2+1;
}
else if(x>y)
{
r=(l+r)/2-1;
}
a=y;
}
printf("! %d",l);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3848kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3740kb
input:
10 1 2 3 4 5 5
output:
? 1 ? 5 ? 6 ? 8 ? 9 ? 9 ! 9
result:
wrong answer Wrong favorite light!