当前位置: 首页 > 工具软件 > plane-game > 使用案例 >

F - Game on Plane (sg函数)

罗华翰
2023-12-01

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个点,两个人轮流连线, 线与线不能相交, 问谁能先围成多边形

思路概括:模板题.....

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
//#define int ll
typedef long double ld;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
const double pi = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5 + 5;
int sg[maxn];
int vis[maxn];
void SG(int n)
{
    mem(sg, 0);
    for(int i=1;i<=n;i++)
    {
        mem(vis, 0);
        for(int j=0;j<= i - 2;j++)
        {
            vis[sg[j] ^ sg[i - j - 2]] = 1;
        }
        for(int j=0;j<=n;j++)
        {
            if(!vis[j])
            {
                sg[i] = j;
                break;
            }
        }
    }
}
int main()
{
    int t;
    cin >> t;
    SG(5000);
    while(t--)
    {
        int n;
        cin >> n;
        if(sg[n]) cout << "First" << endl;
        else cout << "Second" << endl;
    }
    return 0;
}

 

 类似资料: