题目

有\(n\)堆石子,每次可以从一堆中取出若干个或是将一堆分成三堆非空的石子,

取完最后一颗石子获胜,问先手是否必胜


分析

它的后继还包含了分成三堆非空石子的SG函数,找规律可以发现

\[SG[x]=\begin{cases}0,x=0\\x-1,x=8k(k\in N^*)\\x+1,x=8k+7(k\in N)\\x,otherwise\end{cases}
\]

判断\(n\)堆石子SG函数异或和不为0则先手必胜


代码

#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
signed main(){
for (rr int T=iut();T;--T){
rr int ans=0;
for (rr int n=iut();n;--n){
rr int x=iut();
switch (x&7){
case 0:{
ans^=x-1;
break;
}
case 7:{
ans^=x+1;
break;
}
default:{
ans^=x;
break;
}
}
}
if (ans) puts("First player wins.");
else puts("Second player wins.");
}
return 0;
}

#Multi-SG#HDU 5795 A Simple Nim的更多相关文章

  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函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

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

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

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

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

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

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

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

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

  8. HDU 5795 A Simple Nim

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

  9. HDU 5794 - A Simple Nim

    题意:    n堆石子,先拿光就赢,操作分为两种:        1.任意一堆中拿走任意颗石子        2.将任意一堆分成三小堆 ( 每堆至少一颗 )        分析:    答案为每一堆的 ...

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

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

随机推荐

  1. Notepad++找回自动保存缓存内容的文件

    在目录C:\Users\Administrator\AppData\Roaming\Notepad++\backup中找到自动保存的缓存文件. 参考Notepad++找回自动保存缓存内容的文件

  2. Conda简单教程

    目录 什么是Conda 安装Conda 虚拟环境管理 模块管理 何时使用Conda 什么是Conda Conda是Python中用于管理包和虚拟环境的一大利器. 使用Conda可以非常便利的使用数据科 ...

  3. ABP的版本升级,从7.2.2升级到7.2.3

    1.升级ABP CLI 见前面的文章:ABP开发需要用到的命令 更新最新版本: ~~~ dotnet tool update -g Volo.Abp.Cli ~~~ 2.升级ABP Suite 见前面 ...

  4. NSSRound#17 Basic web

    NSSRound#17 Basic web 真签到 审题 一个登录界面 看到页面名字Robots? 转到robots.txt 看到加密 知识点: 加密解密. 解题 hint解密,使用Hex加密方式解出 ...

  5. 360 数科实践:JanusGraph 到 NebulaGraph 迁移

    摘要:在本文中 360 数科的周鹏详细讲解了业务从 JanusGraph 迁移到 Nebula Graph 带来的性能提升,在机器资源不到之前 JanusGraph 配置三分之一的情况下,业务性能提升 ...

  6. Java 线程通信 例子:使用俩个线程打印1-100.线程1 线程2 交替打印

    1 package bytezero.threadcommunication; 2 3 /** 4 * 线程通信的例子:使用俩个线程打印1-100.线程1 线程2 交替打印 5 * 6 * 涉及到的三 ...

  7. 并行化优化KD树算法:使用C#实现高效的最近邻搜索

    本文信息 中文名:<并行化优化KD树算法:使用C#实现高效的最近邻搜索> 英文名:"Parallelized Optimization of KD-Tree Algorithm: ...

  8. ansible-vault 教程

    基本使用 在编写playbook时,可能会涉及到一些敏感的数据,比如密码,当这些敏感数据以明文的方式存储在playbook中时,可能是不能被接受的,那么我们该怎么办呢?ansible官方已经考虑到了这 ...

  9. Prometheus技术分享——prometheus的函数与计算公式详解

    Prometheus与zabbix相比,它的强大之处就在于可以它可以使用的很多计算公式去获取自己需要的数据.当然,这里所涉及到的计算公式,也是我们普遍认为的难点所在.比如,我们要获取CPU使用率,使用 ...

  10. 分布式理论 & RPC & Dubbo

    分布式服务框架(RPC) 用于提高机器利用率的资源调度和治理中心*(SOA)[ Service Oriented Architecture] Dubbo(RPC框架) 服务提供者**(Provider ...