C++-POJ2234-Matches Game[Nim][SG函数]
2024-10-08 10:51:01
#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 ;
}
最新文章
- Microsoft Visual C++ Compiler for Python 2.7
- SQL中关于字符串的处理
- .NET中的视图和过滤器 (DefaultView和RowFilter)
- HDU 5387 Clock
- Java_Spring MVC_Servlet
- 10行Java代码实现最近被使用(LRU)缓存
- http协议与内容压缩
- MySQL索引原理与慢查询优化
- Dockerfile制作sshd镜像
- window.open和window.close的使用详解
- samba 开启
- 从花式swap引出的pointer aliasing问题
- YiShop_商城网站建设应该注意什么
- New UWP Community Toolkit
- Centos7下Redis3.2的安装配置与JReid测试
- centos6.5安装Mysql5.6及更改密码
- switch and checkbox
- HDOJ5547 SudoKu
- 149. Max Points on a Line同一条线上的最多点数
- 通用shellcode