Cod sursa(job #2756729)
Utilizator | Data | 2 iunie 2021 18:07:41 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
bool q(int x)
{
cout << "? " << x << '\n';
cout.flush();
cin >> x;
return x;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
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;
}