简单题 WA 四个点倒闭求救
查看原帖
简单题 WA 四个点倒闭求救
906320
Milky_Cat楼主2024/12/26 08:27
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
int pos;
void query(int x){
	cout << "? " << x << "\n";
	cout << flush;
	cin >> s;
}
int a[] = {1, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 1000000000};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	query(a[9]);
	if (s == "Y"){
		for (int i = 9; i >= 2; i--){
			query(a[i] - 1);
			if (s == "N"){
				pos = i;
				break;
			}
		}
		cout << "! " << a[pos];
		cout << flush;
		return 0;
	}
	for (int i = 8; i >= 1; i--){
		query(a[i]);
		if (s == "Y"){
			pos = i;
			break;
		}
	}
	int l = a[pos] + 1, r = a[pos + 1] - 1, ans;
	while (l <= r){
		int mid = (l + r) >> 1;
		query(10 * mid);
		if (s == "Y")
			ans = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	cout << "! " << ans;
	cout << flush; 
	return 0;
}
2024/12/26 08:27
加载中...