【Gym - 101350 E - 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?

Input
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).

Output
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.

Example
Input
2
2
5
Output
second
first

题意 : 给出一行 1 * n 的格子,一开始全是白色的,你可以选择不大于 p <=[L / 2] (向上取整,L为当前连着的最大数量的白色格子)的质数(没有不大于 p 的质数时,p取 1)去填任意 p 个格子,问最后先手和后手,谁最后一个把格子填满

思路 : 模拟几个数会发现,只用在 n 等于 2 或 3 时后手会赢,其余都是先手赢

AC代码:

#include<cstdio>
#include<cmath>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 10;
typedef long long LL;
int main()
{
    int T; scanf("%d",&T);
    while(T--){
        int n,a;
        scanf("%d",&a);
        if(a == 2 || a == 3) puts("second");
        else puts("first");
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值