CF Gym 102059I Game on Plane(sg函数)

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 Copy
2
3
5
output Copy
First
Second

题目描述:给n个点,每次可以选2个点连线,连接的线不能相交,不能连线的输。

思路:考虑两个点连线,把一堆点分成两堆,可以转换成分成2个子游戏,原来的游戏的sg值就是子游戏的sg值xor和。

  假设是点a和点b连成的线把原游戏划分成2个子游戏,因为如果我从子游戏中找任意一点x和a相连,对手总能让x与b相连,不改变胜负结果。所以用来划分的点可以直接丢掉。即游戏n分成i和n-i-2的子游戏,跑一次sg函数。

代码:

#include<bits/stdc++.h>
#define sd(x) scanf("%d",&x)
#define lsd(x) scanf("%lld",&x)
#define ms(x,y) memset(x,y,sizeof x)
#define fu(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> P;
const int N=1e4+99;
const ll mod=2147493647;
const int INF=1e9+7;
int sg[N];
int Sg(int n)
{
    if(sg[n]!=-1) return sg[n];
    set<int> s;s.clear();
    for(int i=0;i<=n&&n-i-2>=0;i++)
    {
        s.insert(Sg(i)^Sg(n-i-2));
    }
    int res=0;
    while(s.count(res)) res++;
    return sg[n]=res;
}
int main() 
{
    int t;sd(t);
    ms(sg,-1);
    sg[0]=0;
    while(t--)
    {
        int n;sd(n);
        if(Sg(n)!=0) puts("First");
        else puts("Second");
    }
    return 0;
}

 

上一篇:博弈论基础


下一篇:在NUnit测试期间的拆解事件中,如何获取应用于刚刚测试的方法的属性?