题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5795

A Simple Nim

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#### 问题描述
> Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more interesting,players can separate one heap into three smaller heaps(no empty heaps)instead of the picking operation.Please find out which player will win the game if each of them never make mistakes.
#### 输入
> Intput contains multiple test cases. The first line is an integer 1≤T≤100, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers s[0],s[1],....,s[n−1], representing heaps with s[0],s[1],...,s[n−1] objects respectively.(1≤n≤106,1≤s[i]≤109)
#### 输出
> For each test case,output a line whick contains either"First player wins."or"Second player wins".
#### 样例
> **sample input**
> 2
> 2
> 4 4
> 3
> 1 2 4
>
> **sample output**
> Second player wins.
> First player wins.

题解

打表找规律,发现只有%8的位置的sg值与之前的一个数交换了,其它的sg值都等于它本身。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
const int maxn = 111; int SG[maxn],vis[maxn+10]; void get_SG() {
SG[0] = 0;
SG[1] = 1;
SG[2] = 2;
for (int i = 3; i < maxn; i++) {
memset(vis, 0, sizeof(vis));
for (int j = 0; j < i; j++) {
vis[SG[j]] = 1;
}
for (int a = 1; a < i; a++) {
for (int b = a; a + b < i; b++) {
int c = i - a - b;
vis[SG[a] ^ SG[b] ^ SG[c]] = 1;
}
}
for (int j = 0;; j++) if (vis[j] == 0) {
SG[i] = j; break;
}
/*printf("%d\n", SG[i]);*/
if (SG[i] != i) printf("%d:%d\n", i,SG[i]);
}
} int main() {
//get_SG();
int tc,n;
scanf("%d", &tc);
while (tc--) {
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
int x; scanf("%d", &x);
if (x % 8==7) ans^=(x+1);
else if (x % 8 == 0) ans^=(x-1);
else ans ^= x;
}
if (!ans) puts("Second player wins.");
else puts("First player wins.");
}
return 0;
}

HDU 5795 博弈的更多相关文章

  1. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  4. HDU 5795 A Simple Nim (博弈 打表找规律)

    A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...

  5. HDU 5795:A Simple Nim(博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description   Two players take t ...

  6. HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

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

  7. hdu 5795 A Simple Nim 博弈sg函数

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

  8. HDU 5795 A Simple Nim ——(Nim博弈 + 打表)

    题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打 ...

  9. HDU 5996 博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=5996 博弈论待补. 这题变化了一下,因为注意到奇数层的东西(层数从1开始),对手可以模仿地动,那就相当于没动. ...

随机推荐

  1. 整理一些有意思的php笔试题

    慢慢补充 1.下面这段代码的输出是什么: $a = in_array('01', array('1'))==var_dump('01'==1); echo $a; 说明:in_array('01', ...

  2. 解决:JS如何取得当前正在执行的function的名字

    代码如下 function getFName(fn){ return (/^[\s\(]*function(?:\s+([\w$_][\w\d$_]*))?\(/).exec(fn.toString( ...

  3. nginx学习笔记1

    Nginx是使用c语言编写的,查看nginx编译时参数的设定  使用nginx -V命令查看 可以使用nginx -h命令查看命令帮助 配置文件中将worker process绑定到cpu的特定内核上 ...

  4. C++ 里 构建动态二维数组

    //****动态二维数组 /* int m=3; int **data; int n=2; data=new int*[m]; for(int j=0;j<m;j++) { data[j]=ne ...

  5. CentOS7.0安装与配置Tomcat-7

    解决权限不够 #chmod a+x filename 安装说明 安装环境:CentOS-7.0.1406安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz 下载地址:ht ...

  6. U6会计科目导入致对账不平

    一个客户,用的是U6版本,想将己使用的账套的科目导入新建的账套中,本想用用友本身自带的总账工具导入,发现导不了.没办法,只能打开数据库,手工导入. 月末结账时,发现对账不平.问题是余额表与明细不平,大 ...

  7. 共享内存shared pool (4):Library cache 转储文件

    上一篇blog只是从概念上理解Library cache,本篇则是将Library cache从内存中dump出来,看看其结构. 基本命令 ALTER SESSION SET EVENTS 'imme ...

  8. stm32f103 SPI单线TX发数据来驱动LCD

    有一黑白LCD,有CS/SI/SCK三线,时序满足SPI时序,但STM32的SPI有四线NSS/MOSI/SCK/MISO,这里MISO没有用到.因此可以使用SPI的单线发送模式进行驱动LCD. 关键 ...

  9. C# 获取图片的EXIF 信息

    关于 EXIF 信息的介绍. 1  EXIF,是英文Exchangeable Image File(可交换图像文件)的缩写.EXIF是一种图像文件格式,只是文件的后缀名为jpg.EXIF信息是由数码相 ...

  10. 7.Knockout.Js(Mapping插件)

    前言 Knockout设计成允许你使用任何JavaScript对象作为view model.必须view model的一些属性是observable的,你可以使用KO绑定他们到你的UI元素上,当这些o ...