#Multi-SG#HDU 5795 A Simple Nim
题目
有\(n\)堆石子,每次可以从一堆中取出若干个或是将一堆分成三堆非空的石子,
取完最后一颗石子获胜,问先手是否必胜
分析
它的后继还包含了分成三堆非空石子的SG函数,找规律可以发现
\]
判断\(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的更多相关文章
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu 5795 A Simple Nim 博弈sg函数
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5795 A Simple Nim ——(Nim博弈 + 打表)
题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打 ...
- HDU 5795 A Simple Nim
打表找SG函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...
- HDU 5794 - A Simple Nim
题意: n堆石子,先拿光就赢,操作分为两种: 1.任意一堆中拿走任意颗石子 2.将任意一堆分成三小堆 ( 每堆至少一颗 ) 分析: 答案为每一堆的 ...
- HDU 5795:A Simple Nim(博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description Two players take t ...
随机推荐
- CentOS7安装Chrome及驱动
目录 安装Chrome 更新Chrome 安装Chrome驱动程序 更新Chrome驱动程序 环境:CentOS Linux release 7.4.1708 (Core) 安装Chrome 下载安装 ...
- macOS使用CodeRunner快速配置fortran环境
个人网站:xzajyjs.cn 由于一些项目的缘故,需要有fortran的需求,但由于是M1 mac的缘故,不能像windows那样直接使用vs+ivf这种经典配置.搜了一下网上主流的跨平台方案,主要 ...
- RN运行ios报错No matching function for call to 'RCTBridgeModuleNameForClass'
xcode更新12.5后,ios运行报错No matching function for call to 'RCTBridgeModuleNameForClass' 解决方法: 在ios/Podfil ...
- 第一百零一篇:DOM节点类型
好家伙, DOM DOM是javascript操作网页的接口,全称为文档对象模型(Document Object Model).它的作用是将网页转为一个javascript对象, 从而可以使用ja ...
- mac环境下安装python3的requests包
大家知道,mac环境默认安装的都是python2,自己装好python3之后,怎么使用pip来安装到python3下的包呢? 解决方法:pip3 install requests
- (一)Git 学习之为什么要学习 Git
一.版本控制 1.1 何为版本控制 版本控制(Revision control)是一种在开发的过程中用于管理我们对文件.目录或工程等内容的修改历史,方便查看更改历史记录.备份,以便恢复以前的版本的软件 ...
- 用java实现书城项目(简单增删改查2)
书城项目 登录 dao 接口:UserDao Users login(String username,String password); 实现:UserDaoImpl QueryRunner quer ...
- Spring事务(五)-事务隔离级别
Spring @Transactional注解isolation属性 @Transactional注解通过isolation属性设置事务隔离级别.如下: @Transactional(isolatio ...
- Nginx安装nginx-rtmp-module模块
简介 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展. nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最 ...
- [win10] 开始-设置 / 右键-显示设置 / 右键个性化 等都不好使了。。 ms-settings:display
现象: 各种win10自带的都打不开了. 发现: 最近总是断网,重启下就好了,然后点击网络,就一直出不来.后来发现所有win10的窗口都出不来了.控制面板等等. 解决:好消息是最后解决了.坏消息是没有 ...