题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆

Alice先取,问谁能获胜

思路:首先观察这道题的数据范围  1 ≤ N ≤ 10^6, 1 ≤ 【Si】 ≤ 2^31 - 1,很明显数据量太大,所以只能通过打表找规律

打表后发现,如果x%4==0 sg[x]=x-1 ;如果 x%4==3 sg[x]=x+1;如果 其他情况 sg[x]=x;

代码:

打表代码:

#include <iostream>
#include <cstring>
using namespace std; int sg[]; int get(int n)
{
if(n<) return ;
if(sg[n]!=-) return sg[n];
bool visit[];
memset(visit,false,sizeof(visit));
for(int i=;i<=n/;i++)
visit[get(i)^get(n-i)]=true;
for(int i=;i<=n;i++)
{
visit[get(n-i)]=true;
}
int k;
for(int i=;i<=;i++)
{
if(visit[i]==false)
{
return sg[n]=i;
}
}
} int main()
{
memset(sg,-,sizeof(sg));
sg[]=;sg[]=;
for(int i=;i<=;i++)
{
get(i);
}
for(int i=;i<=;i++)
cout<<i<<" "<<sg[i]<<endl;
return ;
}

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int main()
{
int t;
cin>>t;
while(t--)
{
int n,x,ans=;
cin>>n;
for(int i=;i<=n;i++)
{
scanf("%d",&x);
if(x%==)
ans=ans^(x-);
else if(x%==)
ans=ans^(x+);
else
ans=ans^x;
}
if(ans)
cout<<"Alice"<<endl;
else
cout<<"Bob"<<endl;
}
return ;
}

hdu 3032 Nim or not Nim? (sg函数打表找规律)的更多相关文章

  1. bzoj 1228 [SDOI2009]E&D SG函数打表 找规律

    题目链接 Description 桌子上有2n 堆石子,编号为1..2n.将第2k-1 堆与第2k 堆(1 ≤ k ≤ n)为同一组.第i堆的石子个数用一个正整数Si表示.一次分割操作指的是,从桌子上 ...

  2. Playing With Stones UVALive - 5059 Nim SG函数 打表找规律

    Code: #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...

  3. Light OJ 1296:Again Stone Game(SG函数打表找规律)

    Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains ...

  4. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  5. Nim or not Nim? hdu3032 SG值打表找规律

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

  6. 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho

    以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; i ...

  7. 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  8. Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)

    #include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...

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

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

随机推荐

  1. android学习2——RelativeLayout

    相对布局管理器,一个View的位置是相对于另外一个View定义的. <?xml version="1.0" encoding="utf-8"?> & ...

  2. 最新虚拟机SAP ECC6.0 EHP7带示例数据IDES版+BW740

    学习SAP,需要虚拟机,请联系QQ:858-048-581 版本:ECC6.0 EHP7.虚拟机操作系统:windows server 2008 64bit..数据库:SQL2008 R2.系统已经做 ...

  3. angular destroy & jquery destroy

    destroy的目的是为了内存溢漏,这对性能会造成影响. angular scope在处理element 移除时,会触发destroy, 而调用逻辑和jquery使用的一样. 在ck editor 中 ...

  4. 每天一个Linux命令(16)--which命令

    把昨天的,留给昨天:今日,你将重新开始. 好的,在第一个阶段我们学习了  文件目录的操作命令: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ls cd pwd mkdir ...

  5. 做了个新的UWP类库 Sharp2D

    C#开发UWP的时候如果要实现高斯模糊效果的话,最好的选择似乎是微软的Win2D 但是Win2D太过庞大了,仅仅是庞大其实也没啥问题,毕竟net core就很庞大,但Win2d是一个Winmd组件 w ...

  6. 每天一个Linux命令 5

    命令名称:touch 功能描叙:创建空文件 格式:touch  文件名 范例:$touch japan.list(当前路径创建) $touch  /root/japan.list(指定路径创建) $t ...

  7. html、css、js实现轮播图

    2017-03-13 今天把轮播图的知识1过了一下,写了一个比较简单的轮播图,给大家参考一下. 查看具体的效果点击这个链接 : http://gjhnstxu.me/%E8%BD%AE%E6%92%A ...

  8. java解析上传的excel

    file是一个File,是一个excel文件 得到文件流:InputStream in =  file.getInputStream() 需要引入的类 import jxl.Cell;import j ...

  9. 如何修改SVN客户端中保存的密码

    本文主要讲述Linux命令行下怎么修改已经保存的客户端密码: 第一步,删除 subvision文件: rm -rf ~/.subvision 第二步:执行任意需要访问服务器的svn命令,会提示是否永久 ...

  10. yolov2训练ICDAR2011数据集

    首先下载数据集train-textloc.zip 其groundtruth文件如下所示: 158,128,412,182,"Footpath" 442,128,501,170,&q ...