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)
Total Submission(s): 2513 Accepted Submission(s): 1300
Problem Description
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
Output
Sample Input
3
2 2 3
2
3 3
Sample Output
Bob
分析
打表找规律。
$$
sg(x)=
\begin{cases}
x-1,&x\ mod\ 4=0\\
x+1,&x\ mod\ 4=3\\
x,&else \\
\end{cases}
$$
code
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- int get_SG(int x) {
- if (x%==) return x-;
- else if (x%==) return x+;
- return x;
- }
- int main () {
- int T,n,ans;
- scanf("%d",&T);
- for (int Case=; Case<=T; ++Case) {
- scanf("%d",&n);
- ans = ;
- for (int t,i=; i<=n; ++i) {
- scanf("%d",&t);
- ans ^= get_SG(t);
- }
- if (ans==) puts("Bob");
- else puts("Alice");
- }
- return ;
- }
打表代码
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- int sg[];
- bool Hash[];
- const int N = ;
- void get_SG() {
- for (int i=; i<=N; ++i) {
- memset(Hash,false,sizeof(Hash));
- for (int j=; j<=i; ++j) {
- Hash[sg[j]] = true; // 取石子
- if (j!= && j!=N) Hash[sg[j]^sg[i-j]] = true; //拆分
- }
- for (int j=; ; ++j)
- if (!Hash[j]) {sg[i] = j;break;};
- }
- }
- int main () {
- get_SG();
- /*for (int i=1; i<=10; ++i) {
- for (int j=1; j<=10; ++j) {
- printf("%d ",sg[(i-1)*10+j]);
- }
- puts("");
- }*/
- for (int i=; i<=; ++i) {
- printf("%d ",sg[i]);
- if (i % == ) puts("");
- }
- return ;
- }
HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)的更多相关文章
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- 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 ...
- HDU 4919 Exclusive or (数论 or 打表找规律)
Exclusive or 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/J Description Given n, find ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU 4588 Count The Carries 数位DP || 打表找规律
2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
随机推荐
- python小游戏之贪吃蛇
本程序需要安装pygame,请自行百度安装...... 废话不多说,直接上代码 import pygame,sys,time,random from pygame.locals import * # ...
- vue-cli建立的项目如何在手机端运行以及如何用charles来抓包
刚开始自己在config文件夹下的index.js中的dev下的host写成的是localhost,但是发现自己不能在手机端访问,并且也不可以在charles进行抓包处理,后来把localhost改成 ...
- git 初始化仓库与远程clone
使用命令 git –bare init /home/git/myRep.git,初始化化仓库 在gitClient_01上,通过git clone命令进行克隆远程仓库,并在各自的电脑上运行开发. Gi ...
- 微信企业号升级企业微信后zabbix告警发不出去
首先看下微信的脚本 #!/bin/bash ###SCRIPT_NAME:weixin.sh### ###send message from weixin for zabbix monitor### ...
- C++unsigned char和char区别
char和unsigned charchar与unsigned char都是一个字节8bit,唯一的区别是,char的最高位为符号位,因此char能表示-128~127, unsigned char( ...
- Javascript笔记部分
写入HTML输出 document.write(“<h1>”); 改变HTML内容 x = document.getElementById(“demo”) //查找元素 后面可以.valu ...
- Java第六次作业:RuPengGame setGameSize setGameTitle alert loadBgView playSound pause closeSound confirm input createText setTextPosition setTextColor setTextFontSize hideText showText CreateImage(number)
package com.swift; import java.awt.Color; import com.rupeng.game.GameCore;//导入游戏引擎包 //实现Runnable接口 p ...
- [BZOJ] 2044: 三维导弹拦截
排序去掉一维,剩下两维可以直接\(O(n^2)\)做,也可以用二维树状数组(但是不方便建边),解决第一问 第二问,按转移顺序连边,建出DAG,求最小不可重链覆盖即可 #include<algor ...
- Linux NFS服务器的安装与配置详解
一.NFS服务简介 NFS是Network File System(网络文件系统).主要功能是通过网络让不同的服务器之间可以共享文件或者目录.NFS客户端一般是应用服务器(比如web,负载均衡等),可 ...
- nginx修改nginx.conf配置可以https访问
修改nginx.conf,参照如下更改配置server { listen 443; server_name abc.com; // 访问域名 ssl on; root /var/www/bjubi.c ...