题解:P12531 [XJTUPC 2025] Beat Verdict: Precision Strike
dongzirui0817 · · 题解
思路
发现
于是得到如下表格:
| 区间 | 代表 | 区间 | 代表 |
|---|---|---|---|
事实上不看表格也行。
总之,设第
然后你发现刚好
然后,就没有然后了。
思路
先预处理代表
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll c[20];
int T;
int main() {
c[1] = 2;
for (int i = 2 ; i <= 16 ; i++)
c[i] = (c[i - 1] * 2 + 1) * 2;
for (int i = 1 ; i <= 16 ; i++)
printf("%lld %lld %lld\n", c[i] / 2, c[i], c[i] * 2);
cin >> T;
for (ll n ; T-- ; ) {
cin >> n;
int L = 1, R = 2;
for (int i = 1 ; i <= 16 ; i++)
if (c[i] * 2 < n) ++R;
while (L < R - 1) {
int mid = (L + R) >> 1, k;
cout << "? " << c[mid] / 2 << endl;
cin >> k;
if (k) R = mid;
else L = mid;
}
if (c[L] > n) cout << "! " << n << endl;
else cout << "! " << c[L] << endl;
}
return 0;
}