Cod sursa(job #2798756)

Utilizator Tudor06MusatTudor Tudor06 Data 11 noiembrie 2021 20:24:01
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;

int query( int x ) {
    cout << "? " << x << endl;
    cin >> x;
    return x;
}
int cb( int st, int dr ) {
    int mij;
    while ( st < dr - 1 ) {
        mij = ( st + dr ) / 2;
        if ( query( mij ) == 0 ) {
            st = mij;
        } else
            dr = mij;
    }
    return dr;
}

int main () {
    int n;
    cin >> n;

    int sa_mi_bag____ = cb( 0, n );
    cout << "! " << sa_mi_bag____ << endl;
    return 0;
}