Cod sursa(job #3203640)
Utilizator | Data | 14 februarie 2024 09:25:18 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 30 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
using namespace std;
int query(int X){
cout << "? " << X << endl;
int raspuns;
cin >> raspuns;
return raspuns;
}
int main()
{
int n;
cin >> n;
int st = 1, dr = n, mij;
while(st < dr){
mij = (st + dr) / 2;
if(query(mij) == 1){
dr = mij - 1;
}
else{
st = mij + 1;
}
}
cout << "! " << st << endl;
return 0;
}