Cod sursa(job #2832187)
Utilizator | andrei iorgulescu andreiiorgulescu | Data | 13 ianuarie 2022 09:11:58 |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int st = 1,pas = 1 << 30;
while (pas != 0)
{
int x = st + pas - 1;
if (x <= n)
{
cout << "? " << x << '\n';
cout.flush();
int ans;
cin >> ans;
if (ans == 0)
st = x + 1;
}
pas /= 2;
}
cout << "! " << st << '\n';
cout.flush();
return 0;
}
///nr dorit este mai mare ca intrebare atunci cresc st la intrebare
///nr dorit este mai mic sau egal cu intrebare