跳到正文

题解

题解:P7356 「PMOI-1」游戏

fzs7约 5 分钟
原文
文章信息与版本

文章信息

发布
2024年11月14日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 5 分钟
获赞
6
题目
P7356

版本

  1. v1当前

前方提醒您:输出换行不注意,得到两行 TLE。

首先看到下棋,考虑什么时候必胜,就像五子棋活四是必胜的,形如下图时,我们是必胜的,因为如果对方不堵第二个点,下在第二个点上就赢了,如果堵了,那么下第五个点就好了。

好,接下来开始分讨。

首先对方下了 (0,0)(0,0),我们先下一手 (2,2)(2,2)。

如果对方没有下 (x,y)∈{(1,1),(3,3),(4,4)}(x,y) \in \{(1,1),(3,3),(4,4)\} 的话,我们下一手 (3,3)(3,3) 就是必胜的。

否则我们不管对方下的是其中的哪一个,直接下 (3,0)(3,0)

如果对方不下 (x,y)∈{(1,0),(2,0),(4,0)}(x,y) \in \{(1,0),(2,0),(4,0)\} 的话,我们下一手 (2,0)(2,0) 就变为必胜局面。

否则再次分为三类。

如果对方下 (1,0)(1,0),我们可以下一手 (4,0)(4,0) 来使我们必胜。

如果对方下 (2,0)(2,0),我们就下 (2,3)(2,3)。

如果对方下 (4,0)(4,0),我们就下 (1,3)(1,3)。

然后我们发现以上几种情况都不会超过四步,就做完了。

C++
#include <bits/stdc++.h>
using namespace std;

inline long long read(void) {
	long long x = 0, f = 1; char c = getchar();
	while (c > '9' || c < '0') {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - 48, c = getchar();
	return x * f;
}

long long T, x, y;

int main(void) {
	T = read();
	while (T--) {
		cout << "2 2" << endl;
		x = read(), y = read();
		if ((x != 1 || y != 1) && (x != 4 || y != 4) && (x != 3 || y != 3)) {
			cout << "3 3" << endl;
			x = read(), y = read();
			if (x == 1 && y == 1) cout << "4 4" << endl;
			else cout << "1 1" << endl;
		} else {
			cout << "3 0" << endl;
			x = read(), y = read();
			if (x == 4 && y == 0) {
				cout << "1 3" << endl;
				x = read(), y = read();
				if (x == 3 && y == 1) cout << "0 4" << endl;
				else cout << "3 1" << endl;
			} else if (x == 1 && y == 0) {
				cout << "4 0" << endl;
				x = read(), y = read();
				if (x == 2 && y == 0) cout << "5 0" << endl;
				else cout << "2 0" << endl;
			} else if (x == 2 && y == 0) {
				cout << "2 3" << endl;
				x = read(), y = read();
				if (x == 2 && y == 1) cout << "2 4" << endl;
				else cout << "2 1" << endl;
			} else {
				cout << "2 0" << endl;
				x = read(), y = read();
				if (x == 1 && y == 0) cout << "4 0" << endl;
				else cout << "1 0" << endl;
			}
		}
	}
	return 0;
}
原文