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;
}

F - Game on Plane ( SG博弈 )相关推荐

  1. 【算法与数据结构】—— 博弈论(高阶篇之SG博弈)

    博弈论之SG博弈 SG博弈的命名源于SG函数和SG定理,而SG函数的出现则来自于一个简单的取石子游戏: 有1堆n个的石子,每次只能取{1,3,4}个石子,先取完石子者胜利,判断对于不同的n,先手能否取 ...

  2. 博弈基础与例题分析(巴什博弈威佐夫博弈尼姆博奕 斐波那契博弈SG博弈)

    文章目录 巴什博弈Bash Game 威佐夫博弈Wythoff Game 尼姆博奕 斐波那契博弈:算法如其名 SG博弈 图 mex(minimal excludant)运算 获得sg表 应用 A Br ...

  3. 博弈论学习之巴什博弈,尼姆博弈, sg博弈

    博弈论真是一个神奇的东西,感觉和博弈论厉害的人玩游戏绝对会输. 这个博客讲的很好很全面 此类问题一般有如下特点: 1.博弈模型为两人轮流决策的非合作博弈.即两人轮流进行决策,并且两人都使用最优策略来获 ...

  4. 牛客小白月赛7 B自杀游戏(sg博弈)

    sg博弈结论为,下个状态sg的补集的最小值. 题目 #include<bits/stdc++.h> using namespace std; const int maxn=1e5+9; b ...

  5. hdu 1848(Fibonacci again and again)(SG博弈)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  6. Codeforces Round #724 (Div. 2) F. Omkar and Akmar 组合数学 + 博弈

    传送门 文章目录 题意: 思路: 题意: 思路: 首先我们先来研究一下这个游戏,手画几个会惊奇的发现,后手这个b怎么怎么画都赢啊???对,没错,就是怎么画都赢,下面我们来证明一下为什么后手怎么画都赢. ...

  7. uva 1378 - A Funny Stone Game sg博弈

    题意:David 玩一个石子游戏. 游戏中,有n堆石子,被编号为0..n-1.两名玩家轮流取石子. 每一轮游戏.每名玩家选取3堆石子i,j,k(i<j,j<=k,且至少有一枚石子在第i堆石 ...

  8. HDU1847:Good Luck in CET-4 Everybody!(SG博弈)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 数学基础(四)博弈论(巴什博弈~威佐夫博弈(黄金分割率)~尼姆博奕~斐波那契博弈~SG函数模板)

    一.巴什博弈 1.问题模型 只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个,最后取光者得胜. 2.解决思路: 当n=m+1时,由于一次最多只能取m个,所以无论先取者拿走多 ...

  10. 博弈——NimSG函数函数(hdu1848)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1848 *如对Nim博弈不是很理解的请移步上篇博客http://blog.csdn.net/sm9su ...

最新文章

  1. 框架、文档、视图类之间的调用关系
  2. DIP第一章习题解答
  3. Android系统启动过程全解析
  4. 算法心经.数学的应用.积分的应用
  5. OpenMV常用函数整理
  6. 何必!放着985双一流专业不读,非要当程序员去内卷!
  7. MySQL 浅谈NOT NULL和DEFAULT的关系
  8. 快速图像检索(Deep Learning of Binary Hash Codes for Fast Image Retrieval)
  9. android 编译api,Android逆向利器,直接将apk转换为可二次开发Android工程,提供So hook Api,......
  10. Win10 封装报错处理
  11. 面向对象基础实战——飞机大战
  12. C++的岗位要求是什么?
  13. 网络安全笔记-业务安全
  14. Oracle Contracts Core Tables
  15. Qt Moc及信号-槽源代码解析
  16. 关于面试技巧和简历写法的一些总结
  17. 堪比平板的顶级满血970大屏旗舰解密!荣耀Note10抢先体验!
  18. jquery canvas网页画布画图
  19. Java代码走查审查规范总结
  20. Linux中查看压缩包的内容,linux中肿么查看压缩包中的内容

热门文章

  1. 文件夹正在使用,无法删除 无法重命名等操作怎么办?
  2. python如何控制运行时间_Python控制函数运行时间
  3. 推荐一个免费的论文查重检测软件PaperRight
  4. 含echarts图表の网页打印
  5. Vue的v-model的几种修饰符.lazy的介绍
  6. 有关于反走样的理解(学习笔记仅供参考)
  7. 1807521-02-3,PEP azide,PEP叠氮化物其中叠氮基发生点击反应
  8. 语音信号的短时平均过零率
  9. 全网疯传!最新高频100题汇总(附答案详解)
  10. 视觉算法工程师百度百科,视觉算法工程师是什么