2927: [Poi1999]多边形之战
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 95 Solved: 65
[ Submit][ Status][ Discuss]
Description
多边形之战是一个双人游戏。游戏在一个有n个顶点的凸多边形上进行,这个凸多边形的n-3条对角线将多边形分成n-2个三角形,这n-3条对角线在多边形的顶点相交。三角形中的一个被染成黑色,其余是白色。双方轮流进行游戏,当轮到一方时,他必须沿着画好的对角线,从多边形上切下一个三角形。切下黑色三角形的一方获胜。
注:如果连接一个多边形中任意两点的线段都完全包含于这个多边形,则称这个多边形为凸多边形。
求解任务:
请设计一个程序:
·读入对一个多边形的描述。
·确定先走的一方是否能够获胜。
·将结果输出。
Input
第一行是一个整数, 4 <= n <= 50000。表示多边形的顶点数,多边形的顶点从0到n-1顺时针标号。接着的n-2行描述组成多边形的三角形。第i+1行, 1 <= i <= n-2,有三个空格分隔的非负整数a、 b、 c,它们是第i个三角形的顶点编号。第一个给出的三角形是黑色的。
Output
唯一一行应包含一个单词:
TAK(波兰文“是”),表示先走的一方有必胜策略,或者
NIE(波兰文“否”),表示先走的一方没有必胜策略。
Sample Input
6
0 1 2
2 4 3
4 2 0
0 5 4
0 1 2
2 4 3
4 2 0
0 5 4
Sample Output
TAK
HINT
Source
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
const int maxn = 50050;
int n,tot;
bool bo[maxn];
int getint()
{
char ch = getchar(); int ret = 0;
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <= '9')
ret = ret * 10 + ch - '0',ch = getchar();
return ret;
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
n = getint();
int x = getint(),y,z;
y = getint(); z = getint();
bo[x] = bo[y] = bo[z] = 1;
for (int i = 1; i < n - 2; i++)
{
x = getint(); y = getint(); z = getint();
tot += (bo[x] + bo[y] + bo[z] == 2);
}
if (tot == 1) puts("TAK");
else puts((n & 1) ? "NIE" : "TAK");
return 0;
}