Gym - 101350E-Competitive Seagulls(对称博弈)
There are two seagulls playing a very peculiar game. First they line up N unit squares in a line, all originally colored white.
Let L be the length of the longest continuous sub-segment of white unit squares. Let P be any prime that satisfies the condition that
. The player can choose any P if it satisfies the conditions but if there is no value of P that does, then P is set to 1.
The current player then proceeds to choose any continuous sub-segment of white unit squares of length P and paint them black. The player who can’t make a move loses.
If both players play optimally and the first player starts, which player is going to win the game?
The first line of input is T – the number of test cases.
Each test case contains a line with a single integer N (1 ≤ N ≤ 107).
For each test case, output on a single line "first" (without quotes) if the first player would win the game, or "second" if the second would win.
2 2 5
second first
题意:
有n个格子排成一排,每次能在任意一片区域取连续的一个数x(前提是能取),且x为素数&&x最大为最长区域的1/2(向上取整),如果不存在满足上面两个条件的x,则取1。
所以我们只需要第一次取了之后,让左边的格子数等于右边的格子数即可(第一次从中间取),这样second无论取哪里,我们都能取得对应的那一边。
所以第一次我们必须要能取到2或者3(这样才能满足无论如何都能使左右相等)
所以需要对5以下特判(5/2向上取整等于3,此时first一定能赢)
1->first 2->second 3->second 4->first;
所以只要n不为2或者3,则first赢
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int t,n;
cin >> t;
while(t--){
scanf("%d",&n);
printf((n!=2&&n!=3)?"first\n":"second\n");
}
return 0;
}

浙公网安备 33010602011771号