Cod sursa(job #2756727)
Utilizator | Data | 2 iunie 2021 18:05:41 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
bool q(int x)
{
cout << "? " << x << '\n';
cin >> x;
return x;
}
int main()
{
cin >> n;
int st = 1, dr = n, mid;
bool rasp;
while (st <= dr)
{
mid = (st + dr) >> 1;
rasp = q(mid);
if (rasp)
{
ans = mid;
dr = mid - 1;
}
else st = mid + 1;
}
cout << "! " << ans << '\n';
return 0;
}