Cod sursa(job #2750854)
Utilizator | Alex Luchianov AlexandruLuchianov1 | Data | 13 mai 2021 14:05:16 |
---|---|---|---|
Problema | Cbinteractiv | Scor | Ascuns |
Compilator | cpp-64 | Status | done |
Runda | Marime | 0.47 kb |
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int from = 1, to = n;
while(from < to)
{
int mid = (from + to) / 2;
cout << "? " << mid << "\n";
cout.flush();
int answer;
cin >> answer;
if(answer == 1)
{
to = mid;
}
else
{
from = mid + 1;
}
}
cout << "! " << from << "\n";
cout.flush();
return 0;
}