传送门:

题意:

  给定一个正n边形的点。双方轮流连点成线,要求所画的线不能与之前的线相交。当某个人连成一个回路,这个人就输了。问先手必胜还是后手必胜。

思路:

  SG函数,因为一条线相当于把图劈成了两半,所以每次用异或运算推过来。

/*
* @Author: chenkexing
* @Date: 2019-01-13 16:17:46
* @Last Modified by: chenkexing
* @Last Modified time: 2019-01-15 18:33:24
*/ #include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/*-----------------------showtime----------------------*/
const int maxn = ;
int sg[maxn],s[maxn];
void getsg(int n){ for(int i=; i<=n; i++){
memset(s, , sizeof(s));
for(int j=; j<=i-; j++){
s[(sg[j] ^ sg[i-j-])] = ;
}
for(int j=; ; j++){
if(!s[j]) {
sg[i] = j;
break;
}
}
}
}
int main(){
int T;
getsg();
scanf("%d", &T);
while(T--){
int n; scanf("%d", &n);
if(sg[n])puts("First");
else puts("Second");
} return ;
}

gym/102059/problem/I. Game on Plane SG函数做博弈的更多相关文章

  1. HDU 1848 Fibonacci again and again SG函数做博弈

    传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...

  2. bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)

    1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 733  Solved: 451[Submit][Status ...

  3. HDU-1848-Fibonacci again and again(SG函数,博弈)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意: 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样 ...

  4. nyoj913 取石子(十) SG函数 + Nimm博弈

    思路: 第一堆:SG = n % 3; 第二堆:无规律,打表即可,用hash比set快很多; 第三堆:SG = n; 第四堆:无规律 第五堆:SG = n % 2; 第六堆:SG = n % (i + ...

  5. POJ 2425 A Chess Game 博弈论 sg函数

    http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...

  6. poj 3575 Crosses and Crosses(SG函数)

    Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3063   Accepted: 11 ...

  7. 博弈论初步(SG函数)

    讲解见此博客https://blog.csdn.net/strangedbly/article/details/51137432 理解Nim博弈,基于Nim博弈理解SG函数的含义和作用. 学习求解SG ...

  8. SG函数博弈——poj2311

    关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...

  9. Gym 101246D Fire in the Country(dfs求SG函数)

    http://codeforces.com/gym/101246/problem/D 题意: 给定一个无向有环图,大火从1点开始,每个时间点与它相邻的点也将会着火,现在有两个人轮流操作机器人,机器人从 ...

随机推荐

  1. pyhthon字典练习题

    pyhthon字典练习题: 有如下集合: [11,22,33,44,55,66,77,88,99] 将所有大于55的值保存至第一个KEY值中,将所有小于55的值保存至第二个KEY值中.{"k ...

  2. Shell基本语法---shell脚本的输入以及脚本拥有特效地输出

    shell脚本的输入 语法:read -参数 -p:给出提示符.默认不支持"\n"换行 -s:隐藏输入的内容 -t:给出等待的时间,超时会退出read,单位是秒 -n:限制读取字符 ...

  3. 基于 Autojs 的 APP、小程序自动化测试 SDK

    原文:https://blog.csdn.net/laobingm/article/details/98317394 autojs sdk基于 Autojs 的 APP.小程序自动化测试 SDK,支持 ...

  4. java8中使用函数式接口

    使用函数式接口 Predicate @FunctionalInterface interface Predicate<T>{ boolean test(T t); } public sta ...

  5. 佳木斯集训Day6

    T1还是个找规律啊,记下b的个数,然后直接*2%10000000009就好了 #include <bits/stdc++.h> #define mo 1000000007 using na ...

  6. 假装前端工程师(一)Icework + GitHub pages 快速构建可自定义迭代开发的 react 网站

    icework + gh-pages 超快部署超多模版页面 项目地址:https://github.com/yhyddr/landingpage效果地址:https://yhyddr.github.i ...

  7. Vue小事例

    login <!DOCTYPE html><html lang="ZH-cn"> <head> <meta charset="U ...

  8. 自定义markdown代码高亮显示-cnblog

    这个代码高亮..一点儿都不高亮...... cnblog里已经有闻道先者贴出代码了, https://www.cnblogs.com/liutongqing/p/7745413.html 效果大概是这 ...

  9. Linux常用命令之压缩解压

    压缩是一种通过特定的算法来减小计算机文件大小的机制.这种机制对网络用户是非常有用和高效的,因为它可以减小文件的字节总数,使文件能够通过互联网实现更快传输,此外还可以减少文件的磁盘占用空间.下面简介下z ...

  10. Redhat Linux 系统上安装JDK 1.7

    作者:潇湘隐者 出处:http://www.cnblogs.com/kerrycode/ 步骤1:下载JDK 1.7 安装包  JDK 1.7 下载地址:http://www.oracle.com/t ...