Problem Description
Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap. Nim is usually played as a misere game, in which the player to take the last object loses. Nim can also be played as a normal play game, which means that the person who makes the last move (i.e., who takes the last object) wins. This is called normal play because most games follow this convention, even though Nim usually does not. Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player may either remove any number of objects from a heap or separate a heap into two smaller ones, and the one who takes the last object wins. Input
Input contains multiple test cases. The first line is an integer ≤ T ≤ , the number of test cases. Each case begins with an integer N, indicating the number of the heaps, the next line contains N integers s[], s[], ...., s[N-], representing heaps with s[], s[], ..., s[N-] objects respectively.( ≤ N ≤ ^, ≤ S[i] ≤ ^ - ) Output
For each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes. Sample Input Sample Output
Alice
Bob

Nim or not Nim?

  题目就不说了,解题思路就是SG先打表找规律,简单的尼姆博奕

打表代码 :

 #include <cstdio>
#include <cstring> #define maxn 1000005 int sg[maxn];
bool vis[maxn]; void GetSG()
{
for(int i = ; i <= ; i++)
{
memset(vis , , sizeof(vis));
for(int j = ; j < i ; j++)
vis[sg[j]] = ;
if(i >= )
{
for(int j = ; j < i ; j++)
vis[ sg[j] ^ sg[i-j] ] = ;
}
int mid = ;
while(vis[mid])
mid++;
sg[i] = mid;
printf("%d : %d\n",i,sg[i]);
}
} int main()
{
GetSG();
return ; }

打表结果 

 :
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:

Result

  由于是刚开始接触这种类型的尼姆博弈,说实话对SG还不是很理解,还不能灵活的应用,所以这篇随笔目前也没啥注释,

待我对这类问题有了更清楚的理解,再回来看看这吧。

AC Code :

 #include <bits/stdc++.h>

 int GetSG(int num)
{
if( == num % )
return num - ;
if( == num % )
return num + ;
return num;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n , res = , num;
scanf("%d",&n);
for(int i = ; i <= n ; i++)
{
scanf("%d" , &num);
res ^= GetSG(num);
}
if(res)
printf("Alice\n");
else
printf("Bob\n");
}
return ;
}

  其实这个题和 HDU-5795 http://acm.split.hdu.edu.cn/showproblem.php?pid=5795 神似,(同样的多校赛的题,年份不一样//滑稽)不过就是那个题可以分为3个更小的堆(其实我是先做那个题才做这个的),同样打表找规律,代码稍微修改下就能过,这里就不多说了。

HDU-3032的更多相关文章

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

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

  3. 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 ...

  4. 【hdu 3032】Nim or not Nim?

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

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

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

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

    题目链接 暴力出来,竟然眼花了以为sg(i) = i啊....看表要认真啊!!! #include <cstdio> #include <cstring> #include & ...

  7. hdu 3032 sg打表找规律 *

    有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...

  8. hdu 3032 Nim or not Nim?(搜索打SG表)

    题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) , 也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范 ...

  9. HDU 3032 (Nim博弈变形) Nim or not Nim?

    博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当 ...

  10. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

随机推荐

  1. Android笔记: 实现手机震动效果

    1.震动是系统的服务,首先需添加震动权限 <uses-permission android:name="android.permission.VIBRATE" /> 2 ...

  2. 使用build_opener 自定义 opener

    使用build_opener 自定义 opener,这种方法的好处是可以方便的拓展功能. import urllib.request import http.cookiejar def makeMyO ...

  3. 关于spingMVC使用时配置自动扫描出现的路径报错

    com.lab –controller –service –dao –pojo <context:component-scan base-package=" " /> ...

  4. python自学1——代码优化1

    优化了上次的代码,请求方式可接收get和post两种,代码中对两种方式做了判断. 测试结果中提取了测试用例的名称.请求返回的状态.请求的时间. #coding:utf-8 import xlrd im ...

  5. MyEclipse简介

  6. 通俗易懂的Java序列化原理

    序列化能干吗? (1)通过序列化可以把数据永久地保存到硬盘上(通常存放在文件里) (2)利用序列化实现远程通信,即在网络上传送对象的字节序列. 网上搜索的都是这样的解释,抽象,难懂. 我当时看见这两问 ...

  7. 使用javaconfig配置freemarker

    package com.yy.config; import org.springframework.context.annotation.Bean; import org.springframewor ...

  8. SQL菜鸟学习札记(二)

    五月份一直在写SQL,之后写了一个期末大作业的项目,现在才有时间把之前遇到的各种奇怪的问题整理出来.下一部分札记应该是大作业中使用到的SQL的整理. 一.UPDATE SET语句后面可以并列赋值. 之 ...

  9. chrome开发工具指南(二)

    Application 面板 使用 App Manifest 窗格检查您的网络应用清单和触发 Add to Homescreen 事件. 使用 Service Worker 窗格执行与服务工作线程相关 ...

  10. 【Alpha阶段】第五次 Scrum Meeting

    每日任务 1.本次会议为第 五次 Meeting会议: 2.本次会议在上午09:35,大课间休息时间在陆大召开,召开本次会议为20分钟,汇报自己的任务和讨论接下来的任务: 一.今日站立式会议照 二.每 ...