Codeforces Round #719 (Div. 3)F1. Guess the K-th Zero (Easy version)
F1. Guess the K-th Zero (Easy version)
二分。
以左半部分0的个数为依据。
注意下标从0开始,而题目的下标是从1开始的。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
typedef long long ll;
typedef pair<int, int> PII;
int query(int mid)
{
cout << "? " << 1 << ' ' << mid + 1 << endl;
cout.flush();
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t, n, k;
cin >> n >> t;
cin >> k;
int l = 0, r = n - 1;
while (l < r)
{
int mid = l + r >> 1;
query(mid);
int ans;
cin >> ans;
if (mid - ans + 1 >= k) r = mid;
else l = mid + 1;
}
cout << "! " << l + 1 << endl;
return 0;
}