Cod sursa(job #2760205)
Utilizator | Data | 23 iunie 2021 20:39:43 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
using namespace std;
int cb(int n)
{
int st = 0, 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 - 1;
}
}
return sol;
}
int main()
{
int n;
cin >> n;
int ans = cb(n);
cout << "! " << ans;
return 0;
}