A Simple Nim

Problem Description
 
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.
 
Input
 
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)
 
Output
 
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.
 
题意:
  给你n堆糖果
  A,B两个人可以像nim游戏那样,在一堆中取任意个糖果
  但是此题新增了, 玩家可以将一堆糖果分成三个非空堆,并且不取
  最后取完的胜利;
题解:
  像这种暴力求SG函数会超时的
  咋们就打表找规律
  打表程序已给出,规律你就自己找吧
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+, M = 2e5+, mod = 1e9+, inf = 2e9; int sg[N],vis[N];
int main() {
/*sg[0] = 0;
for(int i = 1; i <= 100; ++i) {
memset(vis,0,sizeof(vis));
for(int j = 0; j < i; ++j) vis[sg[j]] = 1;
for(int j = 1; j <= i; ++j){
for(int jj = 1; jj <= i; ++jj) {
for(int k = 1; k <= i; ++k) {
if(j + jj + k == i) {
vis[sg[j] ^ sg[jj] ^ sg[k]] = 1;
}
}
}
}
for(int j = 0; j <= 1000; ++j) {
if(!vis[j]) {
sg[i] = j;
break;
}
}
cout<<i<<": " << sg[i]<<endl;
}
*/
int T,n,x;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
int ans = ;
for(int i = ; i <= n; ++i) {
scanf("%d",&x);
if((x+)% == ) {
ans ^= (x+);
} else if(x % == ) ans ^= (x-);
else ans ^= x;
}
if(!ans) puts("Second player wins.");else puts("First player wins."); }
return ;
}

HDU 5795 A Simple Nim 打表求SG函数的规律的更多相关文章

  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 ——(Nim博弈 + 打表)

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

  3. HDU 5795 A Simple Nim

    打表找SG函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...

  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(SG打表找规律)

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

  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 1809 求SG函数

    A New Tetris Game(2) Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. hdu_5795_A Simple Nim(打表找规律的博弈)

    题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...

随机推荐

  1. inline-block元素vertical-align的问题分析

    先来解释下这两个标签 inline-block: 字面意思:行内块元素,相当于强制转换,把一个标签设置为行内的块元素,既有块元素的部分特性(支持width\height\maigin-top\marg ...

  2. OperateLoger

    protected void Page_Load(object sender, EventArgs e) { OperateLoger.FunctionInfo =new FunctionInfo { ...

  3. 查看npm全局安装的模块

    1.查看所有高级的npm moudles npm list --depth= 2.查看所有全局安装的模块 npm list --depth= -global

  4. 2016icpc大连站总结(呐 如果把这段回忆,起个名字珍藏起来,叫它“宝物”应该很合适吧)

    10月15号一早乘飞机去了大连,12点这样到了海事大学,是一所很大的学校,来往的学生有些穿着海军服.然后我们到体育馆领了衣服,就去食堂吃午饭,中间有段小插曲,就是我们队的餐券没领..不过那里的负责人让 ...

  5. jvm--3.内存管理

    5.JVM内存管理 JAVA虚拟机在执行java程序的过程中,会把它管理的内存分成若干个不同的数据区域. ----------------------------------------------- ...

  6. Angularjs2 入门

    1.创建文件夹 mkdir angular2-app cd angular2-app 2.配置Typescript 需要通过一些特殊的设置来指导Typesript进行编译.新建一个 tsconfig. ...

  7. Makefile的编写

    makefile介绍 makefile的功能是管理源文件的编译链接,在makefile我们可以定义一系列的规则来指定哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能 ...

  8. sed命令详解

    搜索 纠正错误  添加实例 sed 功能强大的流式文本编辑器 补充说明 sed 是一种流编辑器,它是文本处理中非常中的工具,能够完美的配合正则表达式使用,功能不同凡响.处理时,把当前处理的行存储在临时 ...

  9. bzoj2928: [Poi1999]飞弹

    惨啊…… 被卡常是一种什么感受&…… 很明显的分治. 我们首先可以找到所有点中的最低点,然后对所有点进行一次极角排序,选取一个点使得他各侧飞弹和地堡一样多,并对两侧继续进行分治. 很容易证明这 ...

  10. Ajax深入解析

    AJAX:Asynchronous JavaScript And Xml(异步的JS和XML) 同步:客户端发起请求>服务端的处理和响应>客户端重新载入页面(循环) 异步:客户端实时请求& ...