Cod sursa(job #2806435)
| Utilizator | Data | 22 noiembrie 2021 17:28:39 | |
|---|---|---|---|
| Problema | Cbinteractiv | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("cbinteractiv.in");
ofstream g("cbinteractiv.out");
int n;
int st,dr,mij;
int x;
int query(int nr) {
cout << "? " << nr << '\n';
cin >> x;
return x;
}
int main()
{
cin >> n;
st=1, dr=n;
while (st!=dr) {
mij = (st+dr)/2;
if (query(mij)==1) {
dr = mij;
}
else {
st = mij+1;
}
}
cout << "! " << st;
return 0;
}
