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 ...
随机推荐
- 使用node.js实现apache功能
1.先实现在url中输入文件路径能展示对应文件内容功能 const http = require('http') const fs = require('fs') const server = htt ...
- sass实现头条新闻列表页面
Index.html <!DOCTYPE html> <html> <head> <title>今日头条</title> <meta ...
- 转行小白成长路-java篇
第五章:初始化与清理 前几章怎么看都没发现有什么逻辑顺序,感觉都是相互独立的,在讲述java语言构成的基本单位和规则.这个先放置一边. java中初始化有两层含义,其一是创建,二是赋值. 其本质也就是 ...
- 数据类型(8种)和运算符——Java
一.什么是标识符,它有什么作用(重点掌握) 1. 标识符指的是 标识符是用户编程时使用的名字,用于给变量.常量.函数.语句块等命名,以建立起名称与使用之间的关系.标识符可由任何字母数字字符串形成. 2 ...
- HTML5表单验证(4个实用的表单美化案例)
multipart/form-data 在使用包含文件上传控件的表单时,必须使用autocomplete="on" 自动补全功能novalidate 不验证 <form en ...
- StyleLint 使用指南
StyleLint 是『一个强大的.现代化的 CSS 检测工具』, 与 ESLint 类似, 是通过定义一系列的编码风格规则帮助我们避免在样式表中出现错误. 安装stylelint npm insta ...
- 请求 - Fetch(未完)
概念和用法 可以被使用到更多地应用场景中:无论是service workers.Cache API.又或者是其他处理请求和响应的方式,甚至是任何一种需要你自己在程序中生成响应的方式. Cache 接口 ...
- PWA - Manifest
manifest 在一个JSON文本文件中提供有关应用程序的信息(如名称,作者,图标和描述) manifest 的目的是将Web应用程序安装到设备的主屏幕 部署一个 manifest <link ...
- 安装APACHE到CentOS(YUM)
运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:httpd-2.4.6 硬件要求:无 安装过程 1.安装YUM-EPEL源 HTTP-Tools ...
- 视频格式转换mp4
第一步:https://ffmpeg.zeranoe.com/builds/下载ffmpeg 或者:百度云下载: 链接:https://pan.baidu.com/s/1x_QogbV8xFjkYTe ...