跳到正文

题解

题解:P17558 「FAOI-R15」A Gleam for the Sightless

Subway_hub约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年10月2日
收录
2026年10月2日
更新
2026年11月11日
篇幅
约 4 分钟
题目
P17558

版本

  1. v1当前

比较好玩的构造题目,如何一步步分析这种题目我觉得是比较有价值的。

Hint1

我们可以查询可以确定 clue 位置范围,而且极小。

Hint2

选什么点可以做到?

正解

我们可以通过查询得出 x+yx + y 和 x−yx - y 的值:

  • 开始时,我们查 (1,1)(1,1),根据曼哈顿距离公式,x+y=d+2x + y = d + 2,其中 dd 为返回值。第一次我们随便问一个即可。
  • 第二步非常关键,我们查 (1,m)(1,m),此时因为 clue 会随机移动到上下左右 44 格的位置,但你会发现 x′+y′∈[x+y−1,x+y+1]x' + y' \in [x + y - 1, x + y + 1],又因为 clue 不可能不动,所以只有两种可能(有时会只有一种,因为另外一种不合法,所以答案是唯一的)!我们随机猜一个,如果对了就结束,如果错了另外一个值就一定为 clue 当前值!
  • 第三到七步,我们每次查 (1,1)(1,1),根据上面的铺垫,根据已知求未知,即可。
正确性证明

我们后面猜位置每次有 12\frac{1}{2} 概率猜错(第一次猜的我们就当它 100100% 错即可)。

所以每次都猜错的概率:(12)6(\frac{1}{2})^6。在 50005000 局游戏下,77 次内猜不出只有大约 5050 局左右,稳过。

Code
C++
constexpr int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int n, m; 
int ask(int a, int b){
	cout << a << ' ' << b << endl;
	int d; cin >> d;
	return d;
}
bool query(int a, int b){
	cout << a << ' ' << b << endl;
	int f; cin >> f;
	return f;
}
bool in(int x, int y){
	return x >= 1 && x <= n && y >= 1 && y <= m;
}
vec<pair<int, int>> get(int x, int y){
	vec<pair<int, int>> res;
	for (int i = 0; i < 4; ++i){
		int tx = x + dx[i], ty = y + dy[i];
		if (in(tx, ty)){
			res.eb(tx, ty);
		}
	}
	return res;
}
void Main() {
	cin >> n >> m;
	int sum1 = ask(1, 1) + 2;
	bool find = false;
	find = query(max(1, sum1 - m), sum1 - max(1, sum1 - m));
	if (find){
		return ;
	}
	int sum2 = ask(1, m) - m + 1;
	vec<pair<int, int>> cur;
	for (int i : {sum1 - 1, sum1 + 1}){
		if ((i + sum2) % 2 == 0){
			int x = (i + sum2) / 2, y = (i - sum2) / 2;
			if (in(x, y)){
				bool f = false;
				for (const auto& [i, j] : get(x, y)){
					if (i + j == sum1){
						f = true;
						break;
					}
				}
				if (f){
					cur.eb(x, y);
				}
			}
		}
	}
	find = query(cur[0].first, cur[0].second);
	if (find) return ;
	auto pos = cur[1];
	for (int i = 3; i <= 7; ++i){
		auto tmp = get(pos.first, pos.second);
		sum2 = ask(1, 1) + 2;
		vec<pair<int, int>> tmp2;
		for (const auto& [xx, yy] : tmp){
			if (xx + yy == sum2){
				tmp2.eb(xx, yy);
			}
		}
		find = query(tmp2[0].first, tmp2[0].second);
		if (find) return ;
		if (i == 7) return ;
		pos = tmp2[1];
	}
}
原文
存档评论2 条抓取于