QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574027#6394. Turn on the LighthhhhyfWA 1ms3716kbC++20898b2024-09-18 20:36:212024-09-18 20:36:21

Judging History

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

  • [2024-09-18 20:36:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3716kb
  • [2024-09-18 20:36:21]
  • 提交

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!