Cod sursa(job #3267887)
Utilizator | Data | 12 ianuarie 2025 19:41:56 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int st = 1, dr = n;
int mid, outcome;
while (st <= dr) {
mid = (st + dr) / 2;
cout << "? " << mid << '\n';
cout.flush();
cin >> outcome;
if (outcome == 0) {
st = mid + 1;
}
else {
dr = mid - 1;
}
}
cout << "! " << st << '\n';
cout.flush();
return 0;
}