思路:直接打表找sg函数的值,找规律,没有什么技巧

还想了很久的,把数当二进制看,再类讨二进制中1的个数是必胜或者必败状态。。。。

打表:

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
// #define rson mid+1,r,rt<<1|1
const int N = 1e5+;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
// #define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre(){freopen("in.txt","r",stdin);}
inline int read(){int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;} int g[];
bool vis[];
int sg(int x){
if(g[x] != -) return g[x];
if(x == ) return ;
if(x == ) return ;
if(x == ) return ;
if(x == ) return ;
clc(vis,);
vis[]=;
for(int i = ; i < x; i++){
for(int j=; i+j<x; j++){
int t = ;
int a = sg(i), b = sg(j),c=sg(x-i-j);
t ^= a;
t ^= b;
t^=c;
vis[a] = vis[b] =vis[c]=;
vis[t] = ;
}
vis[g[i]]=;
}
for(int i = ;; i++) if(!vis[i])
return i;
}
int main(){
int n;
clc(g,-);
for(int i = ; i <= ; i++){
g[i] = sg(i);
printf("%d %d\n", i, g[i]);
}
return ;
}

代码:

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
// #define rson mid+1,r,rt<<1|1
const int N = 1e6+;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
// #define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre(){freopen("in.txt","r",stdin);}
inline int read(){int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;} int sg(int x){
if(x%==) return x-;
if(x%==) return x+;
return x;
}
int main(){
int T,n;
scanf("%d",&T);
while(T--){
int sum=;
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
sum^=sg(x);
}
printf("%s\n",sum?"First player wins.":"Second player wins.");
}
return ;
}

多校6 1003 HDU5795 A Simple Nim (sg函数)的更多相关文章

  1. hdu5795 A Simple Nim 求nim求法,打表找sg值规律 给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作可以选择任意一堆取走任意个石子(不可以为空) 或者选择一堆,把它分成三堆,每堆不为空。求先手必胜,还是后手必胜。

    /** 题目:A Simple Nim 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5795 题意:给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作 ...

  2. hdu-5795 A Simple Nim(组合游戏)

    题目链接: A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. HDU5795A Simple Nim SG定理

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  4. hdu 3032 Nim or not Nim? sg函数 难度:0

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. A Simple Nim (SG打表找规律)

    题意:有n堆石子,每次可以将其中一堆分为数量不为0的3堆,或者从其中一堆中拿走若干个,最终拿完的那个人赢. 思路:直接暴力SG状态,然后找出其中的规律,异或一下每一堆的状态就可以了. #include ...

  6. HDU 3032 Nim or not Nim (sg函数)

    加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

  7. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  8. HDU 1729 Stone Game 石头游戏 (Nim, sg函数)

    题意: 有n个盒子,每个盒子可以放一定量的石头,盒子中可能已经有了部分石头.假设石头无限,每次可以往任意一个盒子中放石头,可以加的数量不得超过该盒中已有石头数量的平方k^2,即至少放1个,至多放k^2 ...

  9. [BeiJing2009 WinterCamp]取石子游戏 Nim SG 函数

    Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...

随机推荐

  1. .net与linux

    Mono是什么? http://blog.sina.com.cn/s/blog_693ffe760100k5uh.html Mono是一个开放源代码,Linux版的Microsfot.NET开发平台 ...

  2. No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 问题

    maven编译项目时出错,提示信息如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3 ...

  3. Windows下使用Visual Studio 2010编译ffmpeg全过程

    在visual studio 2010中调用ffmpeg http://blog.sina.com.cn/s/blog_4178f4bf01018wqh.html Windows下使用Visual S ...

  4. Miller-Rabin素数测试学习小计

    1.Miller-Rabin是干啥的?它是用来检测一个数字(一般是很大的数字)是不是素数: 2.Miller-Rabin算法基于的两个定理: (1)费尔马小定理:如果p是一个素数,且0<a< ...

  5. 【转载】git命令和svn的对比

    首先,要明确的是,git和svn是完全不同的两种管理方式.他们的命令不是完全对等的. 下面只是一些相似方法的参考,而已. 参考 http://blog.csdn.net/chen198746/arti ...

  6. open_table

    /* Open a table. SYNOPSIS open_table() thd Thread context. table_list Open first table in list. acti ...

  7. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

  8. BZOJ3856: Monster

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3856 题解:怎么乱搞一下都可以把 代码: #include<cstdio> #in ...

  9. Selenium Tutorial (1) - Starting with Selenium WebDriver

    Starting with Selenium WebDriver Selenium WebDriver - Introduction & Features How Selenium WebDr ...

  10. uva 11624 Fire!(搜索)

    开始刷题啦= = 痛并快乐着,学到新东西的感觉其实比看那些无脑的小说.电视剧有意思多了 bfs裸体,关键是先把所有的着火点放入队列,分开一个一个做bfs会超时的 发现vis[][]是多余的,完全可以用 ...