HDU 5795 A Simple Nim ——(Nim博弈 + 打表)
题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作。
分析:打表找sg值的规律即可。
感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~
打表代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std; int sg[+]; int main()
{
sg[] = ;
for(int i=;i<=;i++)
{
set<int> S;
for(int j=;j<i;j++) S.insert(sg[j]);
for(int a=i-;a>;a--)
{
for(int b=a;b>;b--)
{
for(int c=a;c>;c--)
{
if(a+b+c == i)
{
S.insert(sg[a]^sg[b]^sg[c]);
}
}
}
}
int now = ;
while(S.count(now)) now++;
sg[i] = now;
printf("sg[%d] = %d\n",i,now);
//if(sg[i] != i) printf("sg[%d] = %d\n",i,now);
}
}
AC代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N = (int)1e6 + ; int main()
{
int T;scanf("%d",&T);
while(T--)
{
int n;scanf("%d",&n);
int temp = ,now;
for(int i=;i<=n;i++)
{
scanf("%d",&now);
if(now% == )
{
temp ^= (now-);
}
else if(now% == )
{
temp ^= (now+);
}
else temp ^= now;
}
puts(temp?"First player wins.":"Second player wins.");
}
}
HDU 5795 A Simple Nim ——(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打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- 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 博弈sg函数
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- 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函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...
- HDU 5795:A Simple Nim(博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description Two players take t ...
- HDU 5795 博弈
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Time Limit: 2000/1000 MS (Java/Oth ...
随机推荐
- 解决sql "Compatibility_199_804_30003" 和 "SQL_Latin1_General_CP1_CI_AS" 之间的排序规则冲突。
关联条件加 COLLATE Compatibility_199_804_30003
- webmagic学习之路-3:采集安居客经纪人详情页
这里希望安居客的同行的轻喷!!单纯的做测试,玩玩. 就这么糟践你们的服务器了!!!sorry! 这次学会了webmagic 设置处理的访问HTML返回代码,因为之前一直404的页面process根本都 ...
- JS基础_相等运算符
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 爱上Java诊断利器之Arthas
1. Arthas是什么? 摘自Arthas的Github介绍: Arthas is a Java Diagnostic tool open sourced by Alibaba. Arthas al ...
- Vue访问权限
设置权限 <script> export default { created(){ if(this.$store.state.userStore.role !== 'manager'){ ...
- Java高并发程序设计学习笔记(七):并行设计模式
转自:https://blog.csdn.net/dataiyangu/article/details/87123586 什么是设计模式架构模式设计模式代码模式(成例 Idiom)单例模式普通单例假如 ...
- java开发环境构建
一. 基本工具安装 1. 配置终端命令别名 vim ~/.bash_profile *********************************************** # for colo ...
- mac-svn代码管理
一.mac下svn管理代码 //1.打开命令行工具,cd 到要拉取的代码放置位置 //2.从svn上拉取项目代码:svn checkout svn项目地址 (--username=XXX --pass ...
- pandas中Series对象下的str所拥有的方法(df["xx"].str)
在使用pandas的时候,经常要对DataFrame的某一列进行操作,一般都会使用df["xx"].str下的方法,但是都有哪些方法呢?我们下面来罗列并演示一下.既然是df[&qu ...
- 1.Shell脚本
1.Shell脚本 可以将Shell终端解释器当作人与计算机硬件之间的“翻译官”,它作为用户与Linux系统内部的通信媒介,除了能够支持各种变量与参数外,还提供了诸如循环.分支等高级编 程语言才有的控 ...