Pagini recente » Cod sursa (job #1038935) | Cod sursa (job #2749318) | Cod sursa (job #2761615) | Cod sursa (job #2319291) | Cod sursa (job #3137552)
#include <bits/stdc++.h>
using namespace std;
int verif(int x) {
cout << "? " << x << endl; // vrem sa dea flush
cout.flush();
int raspuns; cin >> raspuns;
// -1 -> query invalid
// 0 -> k > x
// 1 -> k <= x
return raspuns;
}
void afis(int x) {
cout << "! " << x << endl;
cout.flush();
}
int main() {
int n; cin >> n;
// noi cautam o valoare ascunsa k intre [1, n]
int l = 1, r = n;
while(l < r) {
int mid = (l + r) / 2;
if(verif(mid) == true) {
r = mid;
}
else {
l = mid + 1;
}
}
afis(r); // echivalent cu afis(l) fiindca l == r
return 0;
}