gym/102059/problem/I. Game on Plane SG函数做博弈
题意:
给定一个正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函数做博弈的更多相关文章
- HDU 1848 Fibonacci again and again SG函数做博弈
		
传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...
 - bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)
		
1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 733 Solved: 451[Submit][Status ...
 - HDU-1848-Fibonacci again and again(SG函数,博弈)
		
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意: 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样 ...
 - nyoj913 取石子(十) SG函数 + Nimm博弈
		
思路: 第一堆:SG = n % 3; 第二堆:无规律,打表即可,用hash比set快很多; 第三堆:SG = n; 第四堆:无规律 第五堆:SG = n % 2; 第六堆:SG = n % (i + ...
 - POJ 2425 A Chess Game 博弈论 sg函数
		
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...
 - poj 3575 Crosses and Crosses(SG函数)
		
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3063 Accepted: 11 ...
 - 博弈论初步(SG函数)
		
讲解见此博客https://blog.csdn.net/strangedbly/article/details/51137432 理解Nim博弈,基于Nim博弈理解SG函数的含义和作用. 学习求解SG ...
 - SG函数博弈——poj2311
		
关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...
 - Gym 101246D	Fire in the Country(dfs求SG函数)
		
http://codeforces.com/gym/101246/problem/D 题意: 给定一个无向有环图,大火从1点开始,每个时间点与它相邻的点也将会着火,现在有两个人轮流操作机器人,机器人从 ...
 
随机推荐
- 【iOS】App Transport Security
			
iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的HTTP,都转向TLS1.2协议进行传输.这也意味着所有的HTTP协议都强制使用了HTTPS ...
 - 章节十五、5-记录日志---Log4j
			
一.为什么要用Log4j记录日志? 日志记录对于任何应用程序都非常重要. 它可以帮助我们快速调试代码,通过收集代码执行的信息让代码容易维护. 二.Log4j 是什么? Apache为Java提供的日志 ...
 - 通过自制yum源离线安装ansible
			
系统环境 --CentOS release 7 python版本--Python 3.5.4 背景:在企业环境中,安装ansible的服务器往往不能访问互联网,简单的下载ansible源码安装,会 ...
 - Netty源码解析—客户端启动
			
Netty源码解析-客户端启动 Bootstrap示例 public final class EchoClient { static final boolean SSL = System.getPro ...
 - Linux : 性能监测相关命令
			
[参考文章]:Linux命令大全 [参考文章]:Linux 运行进程实时监控pidstat命令详解 1. 进程级别的监测命令 1.1 top top命令可以实时动态地查看系统的整体运行情况,是一个综 ...
 - 关于JVM内存溢出的原因分析及解决方案探讨
			
前言:JVM中除了程序计数器,其他的区域都有可能会发生内存溢出. 0.什么是内存溢出 当程序需要申请内存的时候,由于没有足够的内存,此时就会抛出OutOfMemoryError,这就是内存溢出. 1. ...
 - Amazon S3
			
Amazon S3 是什么? Amazon S3 是亚马逊推出的一款存储服务,名为 Amazon Simple Storage Service,即亚马逊简单存储服务. 有些 S3 的概念需要了解一下: ...
 - Oralce PL/SQL 调用C
			
1.要把C写成扩展的形式 ex.c文件 int __declspec(dllexport) sum(int a,int b) { return a+b; } 2.把C代码编译成动态库(*.dll 或 ...
 - 盘一盘 AQS和ReentrantLock
			
AQS是个啥? AQS(AbstractQueuedSynchronizer)是Java并发用来构建锁和其他同步组件的基础框架.许多同步类实现都依赖于它,如常用的ReentrantLock/Reent ...
 - warpAffine仿射变换
			
仿射变换,其实就是不同的坐标系的相互转换,用于图像的平移和旋转. 首先看一下官方的api描述. https://docs.opencv.org/2.4/modules/imgproc/doc/geom ...