题目链接:

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. Windows7防火墙服务无法启用怎么办

    点击windows 7控制面板中防火墙的“推荐配置”没有反应,打开“服务”,无法启动windows firewall,并报错.  问题:  1.点击windows 7控制面板中防火墙的“推荐配置”没有 ...

  2. CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

    firewall:systemctl start firewalld.service#启动firewallsystemctl stop firewalld.service#停止firewallsyst ...

  3. MySQL5.7重置root密码

    版本更新 缘故,好多网上的教程都不适用了,甚至连官网的文档也不是能够顺利操作的. 如果 MySQL 正在运行,首先杀之: killall -TERM mysqld. 运行mysqld_safe --s ...

  4. jqGrid(2)

    jqGrid使用方法: 原文地址:http://blog.csdn.net/y0ungroc/article/details/12008879 1. 下载文件 1.     下载jqGrid的软件包, ...

  5. Ruby Code Style

    这篇博文逐渐写一点关于Ruby的编码风格,主要参考ruby-stytle-guide. 一些命名准则 函数与变量 使用蛇形小写比较好:some_var, some_function 目录和文件也使用s ...

  6. Microsoft Power BI Designer

    1/25/2015年1月25发布的预览版本,可以通过以下地址下载,注意有x64 和x32 版本区别(和上次PowerMap一样,一般也推荐的使用x64版本) http://www.microsoft. ...

  7. opengl基础学习专题 (三) 多边形绘制的几种样式

    题外话 聪明人之所以不会成功,是由于他们缺乏坚韧的毅力. ——艾萨克·牛顿(1643年1月4日—1727年3月31日)英国 也许可以理解为 想更深一步的时候,坚持,努力和聪明缺一不可. 挺直腰杆在此向 ...

  8. (1)c语言学习总结之从关键字到循环结构

    一.关键字和标示符 1.关键字:c规定的有特殊含义的单词(也就是系统起的名字),全部是小写,有32个; 由关键字引出数据类型和流程类型 1.分类: (1)数据类型:整型用int标示,字符型用char表 ...

  9. ORACLE-12C-RAC INSTALL

    OS: Oracle Linux Server release 5.7 DB: 12.1.0.1.0 挂载镜像:mkdir /media/diskmount /dev/cdrom /media/dis ...

  10. PHP 文件操作函数大全

    <?php 读取文件夹: $handler = opendir("c:\");//打开文件夹 while($dir = readdir($handler)){//遍历文件夹 ...