C++-POJ2234-Matches Game[Nim][SG函数]
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXM=;
int m,a[MAXM],sg[MAXM];
//对于所有的sg[x]状态先默认为0,即必败
//sg(x)=mex{sg(y)|y是x的后继}
//即sg(y)集合中,未出现的最小非负整数
//这里利用xor异或的特殊性质,将sg(x)=sg(y1)^...^sg(yk)
//sg(x)>0为必胜,sg(x)=0为必败
int main(){
while(scanf("%d",&m)!=EOF){
memset(sg,,sizeof(sg));
for(int i=;i<=m;i++)scanf("%d",&a[i]);
for(int i=;i<=m;i++)sg[i]=sg[i-]^a[i];
puts(sg[m]?"Yes":"No");
}
return ;
}
C++-POJ2234-Matches Game[Nim][SG函数]的更多相关文章
- 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 ...
- 多校6 1003 HDU5795 A Simple Nim (sg函数)
思路:直接打表找sg函数的值,找规律,没有什么技巧 还想了很久的,把数当二进制看,再类讨二进制中1的个数是必胜或者必败状态.... 打表: // #pragma comment(linker, &qu ...
- HDU 3032 Nim or not Nim (sg函数)
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 1729 Stone Game 石头游戏 (Nim, sg函数)
题意: 有n个盒子,每个盒子可以放一定量的石头,盒子中可能已经有了部分石头.假设石头无限,每次可以往任意一个盒子中放石头,可以加的数量不得超过该盒中已有石头数量的平方k^2,即至少放1个,至多放k^2 ...
- HDU 3032 Nim or not Nim?(sg函数)
题目链接 暴力出来,竟然眼花了以为sg(i) = i啊....看表要认真啊!!! #include <cstdio> #include <cstring> #include & ...
- S-Nim POJ - 2960 Nim + SG函数
Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> ...
- [BeiJing2009 WinterCamp]取石子游戏 Nim SG 函数
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...
- Playing With Stones UVALive - 5059 Nim SG函数 打表找规律
Code: #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...
- poj-2234 Matches Game Nim
Matches Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13264 Accepted: 7712 Des ...
随机推荐
- opencv —— HoughCircles 霍夫圆变换原理及圆检测
霍夫圆变换原理 霍夫圆变换的基本原理与霍夫线变换(https://www.cnblogs.com/bjxqmy/p/12331656.html)大体类似. 对直线来说,一条直线能由极径极角(r,θ)表 ...
- jdk1.7、jdk1.8兼容共存环境配置方案
前提:环境变量配置 JAVA_HOME=%JAVA_HOME8% JAVA_HOME8=E:\jdk1.8.0_40 JAVA_HOME7=E:\jdk1.7.0_51 path 一.jdk是绿色免安 ...
- AGC011-E Increasing Numbers
题意 给定一个数\(n\),\(n≤10^{500,000}\),问\(n\)最少可以拆分成几个不降数的和.一个不降数是在十进制位下,从高位往低位看,每个数都不会比高位的数更小的数 做法 不降数可以拆 ...
- GCD相关
板子: ? gcd(b, a % b) : a; } POJ1930 题意:给你一个无限循环小数,给到小数点后 9 位,要求这个数的分数形式. 解法: 要想解决这道题,首先应该了解如何将循环小数化为分 ...
- java基础--------arraylist(动态数组)和linkedlist(双向链表)的区别
arraylist使用数组存储数据,所以这样存储的数据根据索引查询的数据速度快,但是新增或者删除元素时需要设计到位移操作,所以比较慢. linkedlist使用双向链表方式存储数据,每个元素都记录前后 ...
- P3902 递增
链接:P3902 ----------------------------------------- 这道题就是最长上升子序列的模板题,因为我们修改的时候可没说不能改成小数(暴力) --------- ...
- HashMap (JDK1.8) 分析
一.HashMap(JDK1.8) 1.基本知识.数据结构 (1)时间复杂度:用来衡量算法的运行时间. 参考:https://blog.csdn.net/qq_41523096/article/det ...
- ES6 DEMO
案例: ①匿名封装 (function(window,document){ const HEAD = 1; let MSG = function(options){ this._init(option ...
- c++精度
- 学习django3过程中的坑
最近跟着Django by Example 2015学习,可老想用最新版的Django3.在学的过程中可踩了不少坑. 今天就又碰到一个: 在这本书中96页有这样的代码: url(r'^login/$' ...