题解:P7356 「PMOI-1」游戏
前方提醒您:输出换行不注意,得到两行 TLE。
首先看到下棋,考虑什么时候必胜,就像五子棋活四是必胜的,形如下图时,我们是必胜的,因为如果对方不堵第二个点,下在第二个点上就赢了,如果堵了,那么下第五个点就好了。
好,接下来开始分讨。
首先对方下了
如果对方没有下
否则我们不管对方下的是其中的哪一个,直接下
如果对方不下
否则再次分为三类。
如果对方下
如果对方下
如果对方下
然后我们发现以上几种情况都不会超过四步,就做完了。
#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;
}