Cod sursa(job #2750999)
| Utilizator | Data | 13 mai 2021 20:33:26 | |
|---|---|---|---|
| Problema | Cbinteractiv | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
int ask(int x) {
cout << "? " << x << '\n';
cout.flush();
int ans;
cin >> ans;
return ans;
}
int main() {
int N;
cin >> N;
int st = 1, dr = N, mid;
while(st <= dr) {
mid = (st + dr) >> 1;
int ans = ask(mid);
if(ans == 0) {
st = mid + 1;
} else if(ans == 1) {
dr = mid - 1;
} else {
return 0;
}
}
cout << "! " << st << '\n';
return 0;
}
