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

F - Game on Plane 【博弈论-SG函数&NIM游戏】

周枫涟
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\leq T\leq 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\leq N\leq 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.

Sample 1

InputcopyOutputcopy
2
3
5
First
Second

Sponsor

每种局面经过move会形成两种局面根据NIM游戏进行xor操作

根据sg函数mex{后继sg}若为0则是必败态,否则是必胜态

#include <math.h>
#include<queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <vector>
#define PI acos(-1)
#include <string.h>
using namespace std;
const int N = 2005, M = 1e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
const double esp = 1e-6;
typedef pair<int, int> PII;
int t;
int n,m;
int sg[5005];
int via[5005];
void getsg()//初始化SG函数
{
    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<=5005;j++)
       {
        if(via[j]==0)
        {
            sg[i]=j;
            break;
        }
       }
    }
}
int main() {
    getsg();
    scanf("%d",&t);
    while(t--)
    {
      scanf("%d",&n);
      if(sg[n]==0)printf("Second\n");//为0是必败态
      else printf("First\n");
    }
    return 0;
}

 类似资料: