QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106197 | #6394. Turn on the Light | blzgods# | WA | 3ms | 3480kb | C++11 | 637b | 2023-05-16 21:17:11 | 2023-05-16 21:17:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,k=0;
bool b[1000010]={false};
int main()
{
cin>>n;
cout<<"? 1"<<endl;
cin>>m;//获取交流的值
int i=1,j=n,mid=n/2+1;
if(m==0) cout<<"! 1"<<endl;
else
{
while(m!=k)
{
cout<<"? "<<mid<<endl;//询问中间的结果
k=m;//保存上一个回答
cin>>m;//接受回答
if(m>k) //mid在左边
{
i=mid;
}
else if(k>m) // mid在右边
{
j=mid;
}
else //mid就是其本身
{
cout<<"! "<<mid<<endl;
return 0;
}
mid=(i+j)/2;
if(j-i<=2) mid+=1;
}
}
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3364kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3480kb
input:
10 1 0 1 2 2
output:
? 1 ? 6 ? 3 ? 4 ? 6 ! 6
result:
wrong answer Wrong answer, more than 1 possible light!