Cod sursa(job #2888240)

Utilizator MihaiZ777MihaiZ MihaiZ777 Data 10 aprilie 2022 20:47:10
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
using namespace std;

int n;

int main()
{
    cin >> n;

    int lf = 1;
    int rg = n;

    while (lf != rg)
    {
        int mid = (lf + rg) / 2;
        cout << "? " << mid << '\n';
        cout.flush();

        int ans;
        cin >> ans;
        if (ans == 0)
        {
            lf = mid + 1;
        }
        else if (ans == 1)
        {
            rg = mid;
        }
        else
        {
            return 0;
        }
    }

    cout << "! " << lf << '\n';
}