cf1019 B. The hat(交互题,二分)
见这篇题解
https://blog.csdn.net/weixin_43960414/article/details/104169784
int n;
int ask(int i) {
ll a1, a2;
cout << "? " << i << endl; cin >> a1;
cout << "? " << i+n/2 << endl; cin >> a2;
return a1 - a2;
}
signed main() {
cin >> n;
int ans0 = ask(1);
if(ans0 == 0) return cout << "! 1" << endl, 0;
if(ans0 & 1) return cout << "! -1" << endl, 0;
int l = 1, r = n/2;
while(l < r) {
int mid = l + r >> 1, ans1 = ask(mid);
if(ans1 == 0) return cout << "! " << mid << endl, 0;
if(ans1 & 1) return cout << "! -1" << endl, 0;
if(ans1 * ans0 < 0) r = mid; else l = mid + 1;
}
cout << "! " << l << endl;
}