Cod sursa(job #3137553)
| Utilizator | Data | 13 iunie 2023 13:40:51 | |
|---|---|---|---|
| Problema | Cbinteractiv | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#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 rasp = 0;
for(int pas = (1 << 30); pas > 0; pas /= 2) {
if(rasp + pas <= n && verif(rasp + pas) == false) rasp += pas;
}
afis(rasp + 1); // echivalent cu afis(l) fiindca l == r
return 0;
}