题意:在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博弈 + 打表)的更多相关文章

  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打表找规律)

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

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

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

  4. HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

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

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

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

  6. HDU 5795 A Simple Nim 打表求SG函数的规律

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

  7. HDU 5795 A Simple Nim

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

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

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

  9. HDU 5795 博弈

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Time Limit: 2000/1000 MS (Java/Oth ...

随机推荐

  1. spring-cloud 学习二 服务发现

    注册中心服务发现的例子 添加module pom文件如下 <?xml version="1.0" encoding="UTF-8"?> <pr ...

  2. Winform_chart控件_心得

    效果图: 1.首先,在工具箱找到chart控件,拖到窗体中. 2.关于chart控件的细节设计: series集合设计: chartType可以选择折线图.柱状图.圆饼图等等. isValueShow ...

  3. spring-test跟junit结合单元测试获取ApplicationContext实例的方法

    步骤 1.继承AbstractJUnit4SpringContextTests 2.引入ApplicationContext   示例代码:(可以根据name或者类型获取bean) import or ...

  4. centos配置vsftpd服务2

    ftp搭建 一.搭建前提a.ssh服务已经开启,b.防火墙关闭,c.连网1.查看ssh和防火墙的状态 service sshd status service iptables status 2.开启s ...

  5. 1 c# 获取当前正在运行的类的程序集

    public static Assembly CurrentAssembly { get { return Assembly.GetExecutingAssembly(); } }

  6. php迭代器Iterator接口

    以前也看过迭代器Iterator接口,感觉不如yied好用,因此实际工作中并没有用到过. 今天看了一篇网上的博客(https://www.cnblogs.com/wwjchina/p/7723499. ...

  7. 9月24日开始发布,主打安全的Librem 5 Linux手机

    曾推出搭载PureOS Linux发行版本Librem笔记本系列的硬件厂商Purism,今天正式宣布了Librem 5 Linux手机的最终和官方发售日期.Librem 5于2017年10月正式发布, ...

  8. OSG入坑之路[转]

    转载自:https://segmentfault.com/a/1190000010506374?utm_source=tag-newest osg插件原理:https://blog.csdn.net/ ...

  9. springboot中使用filter用配置类方式

    在03-springboot-web的Filter包下,创建HeFilter类 代码示例: package com.bjpowernode.springboot.filter; import java ...

  10. 美登杯”上海市高校大学生程序设计邀请赛 Problem E 、 小 花梨 的数组 (线段树)

    Problem E E . 小 花梨 的数组 时间限制:1000ms 空间限制:512MB Description 小花梨得到了一个长度为