Cod sursa(job #2832620)
| Utilizator | Data | 13 ianuarie 2022 23:20:17 | |
|---|---|---|---|
| Problema | Cbinteractiv | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 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;
cout.flush();
int raspuns;
cin >> raspuns;
cout.flush();
if (raspuns == 0)
{
st = mij + 1;
}
else if (raspuns == 1)
{
dr = mij - 1;
sol = mij;
}
}
cout << "!" << ' ' << sol << '\n';
cout.flush();
return 0;
}
