思路:直接打表找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. TCoolMemo

    我们先起个名字叫做TCoolMemo.以上篇已经讲了很多组件的技术,这里就只说出几个重点.其余不多说了. 首先,该Memo从CustomMemo继承,它有这样外观:属于平面的,边框是可以设置颜色的线, ...

  2. MVVM 代码记录

      一.XML <Page x:Class="MVVM.MainPage" xmlns="http://schemas.microsoft.com/winfx/20 ...

  3. Hibernate配置文件hbm主键的generator可选项

    Hibernate配置文件hbm主键的generator可选项 1.自动增长identity 适用于MySQL.DB2.MS SQL Server,采用数据库生成的主键,用于为long.short.i ...

  4. Maven Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean Failed to delete access_log

    I'm trying to run simple struts project using maven and tomcat. When I'm trying to exucute next goal ...

  5. C++:基类与派生类对象之间的赋值兼容关系

    4.5 基类与派生类对象之间的赋值兼容关系 在一定条件下,不同类型的数据之间可以进行类型转换,例如可以将整型数据赋给双精度型变量. 在赋值之前,先把整型数据转换为双精度型数据,然后再把它双精度型变量. ...

  6. tahoma字体对中文字的影响

    一提到tahoma字体大家都会想到,它是一个英文字体,对中文不会有影响. 但是今天就遇到一个问题,tahoma字体会影响中文字的显示,如: html代码: <div class="bo ...

  7. UVa 12661 (单源最短路) Funny Car Racing

    题意: 有一个赛车跑道,可以看做一个加权有向图.每个跑道(有向边)还有一个特点就是,会周期性地打开a秒,然后关闭b秒.只有在赛车进入一直到出来,该跑道一直处于打开状态,赛车才能通过. 开始时所有跑道处 ...

  8. WebServices生成发布过程及常见问题的解决方法

    春夏秋冬走健康之路看四季养生网 健康饮食 养生问题 母婴保健 养生小常识 3.下一步,我们需要将Myservice文件夹拷贝到C:\Inetpub\wwwroot目录下(重要).如下图所示  然后依次 ...

  9. sql 游标循环当中重新赋值

    sql 游标循环当中的变量必须重新赋值不然变量的值就是前次循环的值

  10. IOS cocos2d笔记1

    结点添加.删除.获取1.结点:CCNode * childNode = [CCNode node]; 2.加入结点[myNode addChild:childNode z:0 tag:123];//z ...