Cod sursa(job #2943480)
Utilizator | Data | 21 noiembrie 2022 00:46:37 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
using namespace std;
int n,st,dr,ans,sol;
int main()
{
cin >> n;
st = 1, dr = n;
/// 1 1 1 1 1 0 0 0 0
/// ^
while(st <= dr){
int mid = (st+dr)/2;
cout << "? " << mid << "\n";
cout.flush();
cin >> ans;
if(ans){
sol = mid;
st = mid+1;
}else{
dr = mid-1;
}
}
cout << "! " << sol << "\n";
return 0;
}