Cod sursa(job #2760209)
Utilizator | Data | 23 iunie 2021 20:49:57 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int st = 1, dr = n, sol = -1;
while (st < dr)
{
int mijl = (st + dr) / 2;
cout << "? " << mijl << "\n";
cout.flush();
int ras;
cin >> ras;
if (ras == 1)
{
sol = mijl;
st = mijl + 1;
}
else if (ras == 0)
{
dr = mijl;
}
else
{
return 0;
}
}
cout << "! " << sol;
return 0;
}