HDU 3032 Nim or not Nim? (需求的游戏SG功能)
意甲冠军:经典Nim游戏转换,给你n礧pi,每个堆栈有pi石头,
Alice和Bob轮流石头,意一堆中拿走随意个石子,也能够将某一堆石子分成两个小堆
(每堆石子个数必须不能为0)。先拿完者获胜
思路:求SG函数后找规律。
SG函数定义及求法:点击打开链接
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define INF 1e8
#define eps 1e-8
#define LL long long
#define maxn 1000001
#define PI acos(-1.0) int sg[maxn],vis[maxn]; void SG()
{
sg[0]=0;
sg[1]=1;
for(int i=2;i<100;i++)
{
memset(vis,0,sizeof(vis));
for(int j=i-1;j>=0;j--)
{
vis[sg[j]]=1;
}
for(int j=1;j<i;j++)
{
int state=sg[j]^sg[i-j];
vis[state]=1;
}
for(int j=0;j<maxn;j++)
{
if(!vis[j])
{
sg[i]=j;
break;
}
}
}
for(int i=97;i<maxn;i+=4)
{
sg[i]=i;
sg[i+1]=i+1;
sg[i+2]=i+3;
sg[i+3]=i+2;
}
}
int main()
{
SG();
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int st=0;
for(int i=0;i<n;i++)
{
int a;
scanf("%d",&a);
int p=a%4;
int m;
if(p==0)
{
m=a-1;
}
else if(p==3)
m=a+1;
else m=a;
st^=m;
}
if(st==0)
printf("Bob\n");
else printf("Alice\n");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU 3032 Nim or not Nim? (需求的游戏SG功能)的更多相关文章
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 ...
- 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 ...
- 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 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 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 ...
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
随机推荐
- js实现页面重定位的几种方法
参考地址:http://www.cnblogs.com/super-d2/archive/2011/10/01/2197004.html js实现页面重定向 在现行的网站应用中URL重定向的应用有很多 ...
- Beginning Python From Novice to Professional (4) - 演示样本格式字符串
$ gedit price.py #!/usr/bin/env python width = input('Please enter width: ') price_width = 10 item_w ...
- CentOS 如何使用第三方软件库-EPEL与RPMForge、RPMFusion软件库
在CentOS下运行yum install flash-plugin或yum install mplayer的时候,提示库里没有找到这个软件?为什么会这样?因为CentOS是RHEL编译过来的,去掉了 ...
- NET通用平台
NET通用平台.通用权限.易扩展.多语言.多平台架构框架 先拿出我半前年前平台的设计初稿,经过半年的努力我已经完成了该设计稿的所有功能.并且理念已经远远超出该设计稿. 下面是一些博友对我贴子的评价: ...
- Python3.2官方文档-日志和弱引用
8.5 日志 Logging模块提供了一些功能全面和灵活的日志系统.最简单的形式就是把日志信息发送到一个文件或sys.stderr; import logging logging.debug('Deb ...
- Android开发Thread+Handler演示样本(打地鼠)
直接在代码 package com.mingrisoft; import java.util.Random; import android.app.Activity; import android.o ...
- Oracle SQL Lesson (6) - 使用Join进行联合查询
使用连接SQL 1999SELECT table1.column, table2.columnFROM table1[NATURAL JOIN table2] |[JOIN table2 USING ...
- BI事实上的和维表定义
一个典型的例子是,逻辑业务相比立方体,产品尺寸.时间维度.位置尺寸,分别作为不同的轴.轴的交点是一个详细的事实.这一事实表是多维度的交叉点的一个表.维表是事实的分析的一种形式. 首先介绍下数据库结构中 ...
- Oracle SQL Lesson (7) - 使用子查询
使用子查询简单子查询SELECT select_listFROM tableWHERE expr operator (SELECT select_list FROM table);子查询可以出现在se ...
- vim使用(三):.viminfo和.vimrc
1. viminfo 在vim中操作的行为,vim会自己主动记录下来,保存在 ~/.viminfo 文件里. 这样为了方便下次处理, 如:vim打开文件时,光标会自己主动在上次离开的位置显示. 原来搜 ...