Cod sursa(job #2756728)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 2 iunie 2021 18:06:58
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <bits/stdc++.h>
using namespace std;

int n, ans;

bool q(int x)
{
	cout << "? " << x << '\n';
	cout.flush();
	cin >> x;
	return x;
}

int main()
{
	cin >> n;
	int st = 1, dr = n, mid;
	bool rasp;
	while (st <= dr)
	{
		mid = (st + dr) >> 1;
		rasp = q(mid);
		if (rasp)
		{
			ans = mid;
			dr = mid - 1;
		}
		else st = mid + 1;
	}
	cout << "! " << ans << '\n';
	return 0;
}