Cod sursa(job #2832622)
Utilizator | Data | 13 ianuarie 2022 23:24:12 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int st = 1;
int dr = n;
int sol = -1;
while (st <= dr)
{
int mij = (st + dr) / 2;
cout << "?" << ' ' << mij << '\n';
cout.flush();
int raspuns;
cin >> raspuns;
if (raspuns == 0)
{
st = mij + 1;
}
else if (raspuns == 1)
{
dr = mij - 1;
sol = mij;
}
}
cout << "!" << ' ' << sol << '\n';
cout.flush();
return 0;
}