QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106203#6394. Turn on the LightblzgodsWA 2ms3424kbC++11726b2023-05-16 21:41:122023-05-16 21:41:14

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 21:41:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3424kb
  • [2023-05-16 21:41:12]
  • 提交

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;
        fflush(stdout);
    }
	else
	{
		while(m!=k)
		{
			cout<<"? "<<mid<<endl;//询问中间的结果
			fflush(stdout);
			k=m;//保存上一个回答
			cin>>m;//接受回答
			if(m>k) //mid在左边
			{
				i=mid;

			}
			else if(k>m) // mid在右边
			{
				j=mid;
			}
			else //mid就是其本身
			{
				cout<<"! "<<mid<<endl;
				fflush(stdout);
				return 0;
			}
			mid=(i+j)/2;
			if(j-i<=2) mid+=1;
		}
	}

	cout.flush();
	return 0;
 }

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3368kb

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3424kb

input:

10
1
0
1
2
2

output:

? 1
? 6
? 3
? 4
? 6
! 6

result:

wrong answer Wrong answer, more than 1 possible light!