有谁愿意帮我这个傻逼看看 D 吗
  • 板块灌水区
  • 楼主irrisshirro
  • 当前回复13
  • 已保存回复13
  • 发布时间2022/8/7 00:35
  • 上次更新2023/10/27 16:40:39
查看原帖
有谁愿意帮我这个傻逼看看 D 吗
419487
irrisshirro楼主2022/8/7 00:35

rt,WA 4。

int query(int a, int b) {
	printf("? %d %d\n", a, b);
	fflush(stdout);
	static int ans;
	ans = read<int>();
	if (ans == -1) exit(0);
	return ans;
}

int find_max(int a, int b, int c, int d) {
	int p = query(a, c);
	if (p == 1) 
		return query(a, d) == 1 ? a : d;
	if (p == 0) 
		return query(b, d) == 1 ? b : d;
	if (p == 2) 
		return query(c, b) == 1 ? c : b;
	exit(-1);
}

void solve() {
	int N = read<int>();
	if (N == -1) exit(0);
	if (N == 1) {
		printf("! %d\n", query(1, 2));
		fflush(stdout);
		return;
	}
	std::queue<int> p;
	for (int i = 1; i <= (1 << N); ++i) p.push(i);
	if (N % 2 == 1) {
		int t = 1 << (N - 1);
		while (t--) {
			int a = p.front(); p.pop();
			int b = p.front(); p.pop();
			p.push(query(a, b) == 1 ? a : b);
		}
	}
	while (p.size() != 1) {
		int t = (int)p.size() / 4;
		while (t--) {
			int a = p.front(); p.pop();
			int b = p.front(); p.pop();
			int c = p.front(); p.pop();
			int d = p.front(); p.pop();
			p.push(find_max(a, b, c, d));
		}
	}
	printf("! %d\n", p.front());
	fflush(stdout);
}

int main() {
	int T = read<int>();
	while (T--) solve();
	return 0;
}
2022/8/7 00:35
加载中...