Cod sursa(job #2837660)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 22 ianuarie 2022 13:04:00
Problema Cbinteractiv Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
using ll = long long;
const string fn = "file";

ifstream fin(fn + ".in");
ofstream fout(fn + ".out");

int n, ans;

bool q(int x){
    cout << "? " << x << '\n';
    cout.flush();
    cin >> x;
    return x;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie();
    cin >> n;
    int st = 1, dr = n, mid;
    while(st <= dr){
        mid = (st + dr) >> 1;
        if(q(mid)){
            ans = mid;
            dr = mid;
        }
        else st = mid + 1

    }
    cout << "! " << ans << '\n';
    fin.close();
    fout.close();
    return 0;
}