F - Game on Plane ( SG博弈 )

F - Game on Plane ( sg博弈 )

推荐阅读:https://blog.csdn.net/strangedbly/article/details/51137432

You are given NN points on a plane. These points are precisely the set of vertices of some regular NN-gon. Koosaga, an extreme villain, is challenging you with a game using these points. You and Koosaga alternatively take turns, and in each turn, the player

  1. chooses two of the given points, then
  2. draws the line segment connecting the two chosen points.

Also, the newly drawn line segment must not intersect with any of the previously drawn line segments in the interior. It is possible for two segments to meet at their endpoints. If at any point of the game, there exists a convex polygon consisting of the drawn line segments, the game ends and the last player who made the move wins.

Given the integer NN, Koosaga is letting you decide who will move first. Your task is decide whether you need to move first or the second so that you can win regardless of Koosaga's moves.

Input

The input consists of many test cases. The first line contains an integer TT (1≤T≤50001≤T≤5000), the number of test cases. Each of the following TT test cases is consisted of one line containing the integer NN (3≤N≤50003≤N≤5000).

Output

For each test case, print one line containing the string First if you need to move first or Second if you need to move second so that you can win regardless of Koosaga's moves.

Example

Input

2
3
5

Output

First
Second

 

题意:有n个点,两个人进行游戏,每一次move是连接任意两个点,游戏过程中不能有交叉,当一个人没有点可以连时他就输了。

思路:sg博弈,n=5的子情况有(0,3)(1,2)这一点需要明确,因为子情况是分为两部分的所以需要取一个异或值。

 

代码:

#include<bits/stdc++.h>

using namespace std;

int sg[5005];
int via[5005];

void getsg()
{
    memset(sg,0,sizeof(sg));
    sg[0] = sg[1] = 0;
    sg[2] = 1;
    for ( int i=3; i<=5002; i++ ) {
        memset(via,0,sizeof(via));
        int t = i-2;
        for ( int j=0; j<=t/2; j++ ) {
            via[ sg[j]^sg[t-j] ] = 1;
        }
        for ( int j=0; j<=5002; j++ ) {
            if ( via[j]==0 ) {
                sg[i] = j;
                break ;
            }
        }
    }
}

int main()
{
    getsg();
    int n,listt;
    cin >> listt;
    while ( listt-- ) {
        cin >> n;
        if ( sg[n]==0 ) {
            cout << "Second" << endl;
        }
        else {
            cout << "First" << endl;
        }
    }

    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值