Cod sursa(job #2839685)
Utilizator | Piele Vladut Stefan pielevladut | Data | 26 ianuarie 2022 12:33:56 |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include <bits/stdc++.h>
using namespace std;
int N;
int query(int val)
{
cout << '\n' << '?' << ' ' << val << '\n';
int x;
cin >> x;
return x;
}
int main()
{
cin >> N;
int st = 1, dr = N;
int retine = 0;
while(st <= dr)
{
int mid = (st + dr) >> 1;
int v = query(mid);
if(v == 0)
{
st = mid + 1;
}
else
{
if(v == 1)
{
retine = mid;
dr = mid - 1;
}
}
}
cout << '\n' << "! " << retine << '\n';
}