Cod sursa(job #3208867)
Utilizator | Data | 1 martie 2024 11:42:31 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
using namespace std;
int n;
int st,dr;
int ans;
int query(int x)
{
cout<<"? "<<x<<'\n';
cin>>ans;
return ans;
}
int main()
{
cin>>n;
st=1;
dr=n;
while(st<=dr)
{
int mij=st+(dr-st)/2;
if(query(mij)==1)
dr=mij-1;
else
st=mij+1;
}
cout<<"! "<<st;
return 0;
}