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 ...
随机推荐
- java----FileInputStream类与FileReader类的区别(转)
FileInputStream类与FileReader类的区别:两个类的构造函数的形式和参数都是相同的,参数为File对象或者表示路径的String,它们到底有何区别呢? Readers and W ...
- C#面向对象22 委托事件反射
1.委托的定义:声明委托类型(返回值和参数,命名空间中):定义委托对象 (把委托想象成函数中的占位符~因为你并不确定调用哪个函数~) using System; using System.Collec ...
- sequelize学习笔记
示例: const Sequelize = require('sequelize'); // 建立连接 const sequelize = new Sequelize('test', 'root', ...
- vue入门:(class与style绑定)
对象语法 数组语法 一.对象语法 1.1对象语法绑定HTML Class 语法:v-bind:class="{'className1':boolean1,'className2':boole ...
- 1 asp.net 中如何把用户控件应用于母版页
1 创建用户控件 2 在母版页中注册用户控件 3 使用 <%@ Master Language="C#" AutoEventWireup="true" C ...
- 文本分析:初识Gensim
作者:doze_worm来源:https://www.douban.com/note/620615113/ gensim 起步:本节介绍理解和使用 gensim 所必须的基础概念和术语,并提供一个简单 ...
- 第十章、os模块
目录 第十章.os模块 一.os模块 第十章.os模块 一.os模块 方法 详解 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirn ...
- 平时工作常用linux命令总结
mkdir 创建目录 make dir cp 拷贝文件 copy mv 移动文件 move rm 删除文件 remove # 创建连级目录 mkdir -p a/b/c # 拷贝文件夹a到文 ...
- SQL练习汇总
--1.选择部门30中的所有员工. --2.列出所有办事员(CLERK)的姓名,编号和部门编号. select ename,empno,deptno from emp where job='CLERK ...
- python面向编程:阶段练习
1.所有程序都因该使用面向对象来设计吗?为什么? 不是,面向对象编程优点是扩展性高,对程序员来说不需要关心具体的步骤,只需要调用对象功能,缺点是:程序的复杂度变高,整体的可控性比较低! 2.什么是对象 ...