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 异常捕捉 ( try catch finally ) 你真的掌握了吗?
掌握下面几条原则就可以完全解决“当try.catch.finally遭遇return”的问题. 原则:1.finally语句块中的代码是一定会执行的,而catch块中的代码只有发生异常时才会执行. 2 ...
- C#开发微信公众平台-就这么简单(转载)(附原文链接)
一直使用的是一百八的诺鸡鸭,没有想去接触看起来风风火火的移动互联网:但因工作需要维护一个微信公众订阅号,考虑以前有做网站的基础,就想着做个简单的微信后台管理:看了官方的开发文档,比狗哥地图的短许多,又 ...
- Cognex925B的使用方法
一.Cognex925B的简介 Cognex925B是一款线激光扫描传感器,利用激光三角的原理测量Z方向的断差. 二 ...
- LeetCode:176.第二高的薪水
题目链接:https://leetcode-cn.com/problems/second-highest-salary/ 题目 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Sal ...
- 09 Python之IO多路复用
四种常见IO模型 阻塞IO(blocking IO).非阻塞IO(nonblocking IO).IO多路复用(IOmultiplexing).异步IO(asynchronous IO) IO发生时涉 ...
- element ui input框不能输入的问题(实时学习)
解决: 在input的上面添加数据v-model 既可以 1.菜单中api (2018年8月14号) :default-active 默认根据当前路由选中菜单,值需要和 el-submenu 的属 ...
- Jupyter Notebook不能自动打开浏览器
安装了 Winpython,运行Jupyter Notebook.exe或Jupyter lab.exe,总是不能自动打开浏览器,提示"no web browser found" ...
- Cannot assign to read only property 'exports' of object at webpack ....BaseClient
网上找了很多资料说是import和export不能一起用,改代码 其实根本原因是es6和es5混合使用造成的兼容性问题 只需要配置.babelrc就可以了 首先安装 npm install -D tr ...
- centos 7 安装 LNMPC cacti 1.2.7 监控
先上图,后续更新
- crc32 cpp Makefile可参考
https://github.com/stbrumme/crc32 # simple Makefile CPP = g++ # files PROGRAM = Crc32Test LIBS = -lr ...