ARC070F 题解

发布时间 2023-03-24 17:01:56作者: liangbowen

前言

题目传送门!

更好的阅读体验?

牛逼构造题。

思路

代码

#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
bool query(int x, int y)
{
	cout << "? " << x - 1 << ' ' << y - 1 << endl;
	char ans; cin >> ans; return (ans == 'Y');
}
int a, b, n; bool zlt[114514];
void answer()
{
	cout << "! "; for (int i = 1; i <= n; i++) cout << zlt[i];
	cout << endl;
}
int main()
{
	cin >> a >> b, n = a + b;
	if (a <= b) {puts("Impossible"); return 0;}
	stack <int> stk;
	for (int i = 1; i <= n; i++)
		if (stk.empty()) stk.push(i);
		else
		{
			int top = stk.top();
			stk.push(i);
			if (!query(top, i)) stk.pop(), stk.pop(); //把这两个都丢出去
		}
	int good = stk.top(); //好人
	for (int i = 1; i <= n; i++) zlt[i] = query(good, i);
	answer();
	return 0;
}

希望能帮助到大家!