Cod sursa(job #2751322)
Utilizator | Data | 14 mai 2021 19:39:05 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
using namespace std;
int n;
void cautbin(int from, int to){
if(from >= to){
cout << "! " << from << "\n";cout.flush();
}else{
int mid = (from + to) / 2, c;
cout << "? " << mid << "\n";cout.flush();
cin >> c;
if(c == 1){
cautbin(from, mid);
}else{
cautbin(mid+1, to);
}
}
}
int main() {
cin >> n;
cautbin(1, n);
return 0;
}