题意:

  有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,

也可以选择将这堆石子分成任意的两堆。alice与bob轮流取,取走最后一个石子的人胜利。

思路:

  因为数的范围比较大,所以最好通过SG打表的结果找出规律在解。

打表代码

#include<cstdio>
#include<cstring>
int sg[];
int find(int x)
{
if(sg[x]>=) return sg[x];
bool mex[]= {};
for(int i=; i<x; i++)
{
mex[find(i)]=;//
if(x-i>&&i>) mex[find(i)^find(x-i)]=;
}
int i=;
while(mex[i]) i++;
return sg[x]=i;
}
int main()
{
int n;
memset(sg,-,sizeof(sg));//sg[0]=0;
//printf("%d#",sg[0]);
find();
for(int i=; i<=; i++) printf("%d %d\n",i,sg[i]);
return ;
}

提交代码:

#include<stdio.h>
int x[]={-,,,};
int main()
{
int _case,n,m,ans;
scanf("%d",&_case);
while(_case--)
{
ans=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&m);
ans^=m+x[m%];
}
if(ans)printf("Alice\n");
else printf("Bob\n");
}
}

hdu 3032 Nim or not Nim?(搜索打SG表)的更多相关文章

  1. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  2. hdu 3032 Nim or not Nim? sg函数 难度:0

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. HDU 3032 Nim or not Nim (sg函数)

    加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

  4. HDU 3032 Nim or not Nim? (sg函数求解)

    Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...

  5. HDU 3032 Nim or not Nim? (sg函数)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. HDU 3032 Nim or not Nim?(博弈,SG打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  9. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

随机推荐

  1. My First Django Project - <Django + MySQL + Ajax> (1)

    因为最近工作有些信息需要额外花时间去收集,但是现在有相关的operations每天记录状态,但是没有一个很好的状态收集工具,将状态收集起来,所以很多情况下我们不知道是状态变好了,还是变差.如果使用EX ...

  2. Java 集合转换(数组、List、Set、Map相互转换)

    转自:http://blog.csdn.net/top_code/article/details/10552827 package com.example.test; import java.util ...

  3. ArcGIS Server10.2服务启动不了之http://localhost:6080/arcgis/manager无法打开之arcMap 无法打开6080admin问题解决之路

    遇到的问题:在services.msc中可以正常启动arcGIS server ,但是过几秒种服务就自动关闭, 而且manager打不开, 各种方法都试过了,什么关闭杀毒软件,更改服务配置文件,更改a ...

  4. STL之map

    参见http://www.cplusplus.com/reference/map/map/ template < class Key,                               ...

  5. Android编程小实验

    1.一个layout中存在相同id的控件会出现什么情况?   结论:编译和运行的时候都不会报错,不过使用findViewById()只会获取第一个该id的控件 来自为知笔记(Wiz)

  6. 向Array中添加二分插入排序

    二分插入排序思路 先在有序区通过二分查找的方法找到移动元素的起始位置,然后通过这个起始位置将后面所有的元素后移. 二分插入排序实现 Function.prototype.method = functi ...

  7. 修改Input中Placeholder默认提示颜色(兼容)

    input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { color: #f00; } input:-moz-pl ...

  8. 增强学习————K-摇臂赌博机

    探索与利用增强学习任务的最终奖赏是在多步动作之后才能观察到,于是我们先考虑最简单的情形:最大化单步奖赏,即仅考虑一步操作.不过,就算这样,强化学习仍与监督学习有显著不同,因为机器要通过尝试来发现各个动 ...

  9. RegExp.exec和String.match深入理解

    今天在重新阅读<JavaScript权威指南>的RegExp和String的时候,看到了2个比较容易混淆的函数:RegExp的exec和String的match 这2个函数都是从指定的字符 ...

  10. UVALive - 6572 Shopping Malls floyd

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48416 Shopping Malls Time Limit: 3000MS 问题描述 We want to ...