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. 网站设置404页面 --nginx

    有的时候根据域名要先知道用的什么web 服务器 最简单的 http://tool.chinaz.com/pagestatus/  输入域名,看返回的头部信息 用的那个web浏览器 下面的方法也是根据头 ...

  2. mysqldump数据库同步遇到的问题

    1.同步数据是遇到 没有 lock database权限,报 " mysqldump: Got error: 1044: Access denied for user 'spider_dat ...

  3. mysql导出部分表数据

    mysqldump -uroot -p -h 192.168.1.11 -P 3306 mojiarticle UID_IMEI --where "ID > 1021230 and I ...

  4. my97中文乱码问题

    在使用my97日期插件后页面显示中文乱码问题: 解决方法: 把下面这段代码复盖到你的ZH-CN.js就解决了 var $lang={ errAlertMsg: "\u4E0D\u5408\u ...

  5. codeforces682A

    题目:http://codeforces.com/problemset/problem/682/A 理解: 比较简单的一道题 思路很重要 #include<iostream>//***** ...

  6. 前后端分离中,Gulp实现头尾等公共页面的复用

    前言 通常我们所做的一些页面,我们可以从设计图里面看出有一些地方是相同的.例如:头部,底部,侧边栏等等.如果前后端分离时,制作静态页面的同学,对于这些重复的部分只能够通过复制粘贴到新的页面来,如果页面 ...

  7. linux 批量删除进程

    2016年11月18日 13:11:10 星期五 ps -ef | grep pname | awk '{print $2}' | xargs kill 解释: 杀掉所有包含 'pname' 的进程

  8. C++ Bitstream类

    从raknet上剥下来的 比较适用于前后端通讯,可以对BitStream进行二次封装,方便使用. BitStream.h: #ifndef __BITSTREAM_H #define __BITSTR ...

  9. JDBC连接数据库

    JDBC连接数据库 1.加载JDBC驱动程序. Class.forName("com.mysql.jdbc.Driver"); 建立连接,. Connection conn = D ...

  10. MFC如何读取XML

    <?xml version="1.0" encoding="utf-8"?> <Cases> <case> <No&g ...