CF277C.Game
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1 × 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an n × m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
两名玩家进行如下游戏:初始时,玩家拥有一把刀和一张矩形纸片,该纸片被划分为若干单位大小的正方形网格单元。双方轮流进行操作,无法进行操作的一方判负。每次操作中,玩家可持刀沿任意一条网格线上的线段(不必从纸片边界一端切至另一端)进行切割;凡与刀接触过的纸片部分均被视为已被切割。为防止游戏陷入无限循环,规定每次操作必须切割尚未被切割过的纸片部分(即刀必须至少接触一块此前未被切割的区域)。
显然,当整张纸片被完全切割为 1×1 的小方块时,游戏结束。游戏过程中,纸片各部分不得移动;亦禁止沿纸片外边界进行切割;每次切割的两个端点坐标必须均为整数。
现给定一张 n×m 的纸片,其中已有 k 条切割线。你的任务是判断:若双方从此刻起开始博弈,且均采取最优策略,则哪位玩家获胜?若先手玩家获胜,你还需找出一个必胜的首次操作(即第一条切割线)。
输入格式
The first line contains three integers n, m, k (1 ≤ n, m ≤ 109, 0 ≤ k ≤ 105) — the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xb__i, yb__i, xe__i, ye__i (0 ≤ xb__i, xe__i ≤ n, 0 ≤ yb__i, ye__i ≤ m) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
第一行包含三个整数 n、m、k(1≤n,m≤109,0≤k≤105)——分别表示纸张的尺寸以及已有的切痕数量。接下来是 k 行,每行包含四个整数 xbi, ybi, xei, yei(0≤xbi,xei≤n,0≤ybi,yei≤m)——表示第 i 条切痕两个端点的坐标。
保证每条切痕长度非零,且要么为竖直方向,要么为水平方向,并且不与纸张边界重合。
切痕之间可能相交、重叠,甚至完全相同。也就是说,这些切痕并不一定来自于某次合法的游戏过程。
输出格式
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
如果第二名玩家获胜,则输出 "SECOND"。否则,第一行输出 "FIRST",第二行输出第一名玩家的任意一个必胜操作(即切割端点的坐标,按输入格式输出)。
输入输出样例
输入#1
2 1 0
输出#1
FIRST 1 0 1 1
输入#2
2 2 4 0 1 2 1 0 1 2 1 1 2 1 0 1 1 1 2
输出#2
SECOND
输入解题思路,AI测评打分。不知道怎么写?