【codeforces 768E】Game of Stones
【题目链接】:http://codeforces.com/contest/768/problem/E
【题意】 
 
NIM游戏的变种; 
要求每一堆石头一次拿了x个之后,下一次就不能一次拿x个了; 
问你结果
【题解】 
 
用二进制来表示哪些数字被用过; 
然后写一个记忆化搜索; 
从上到下获取1..60的sg函数 
枚举用了哪个数字,然后总数减掉它,可以使用的数字的状态改变; 
往下走就好; 
一定要记住 
sg函数的最小值是0 
从1开始的话会wa。。 
 
【Number Of WA】 
 
5 
 
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;
int n, ju;
map <LL, int> dic[N];
LL sg[N], pre[N];
LL dfs(int x, LL zt) {
    //printf("%d\n", x);
    if (dic[x].count(zt))
        return dic[x][zt];
    LL ret = 0;
    for (LL i = 0; i <= x-1; i++)
        if (zt&pre[i]) {
            ret |= pre[dfs(x - i-1, zt ^ pre[i])];
        }
    for (LL i = 0; i <= x; i++)
        if ((ret&pre[i]) == 0)
            return dic[x][zt] = i;
}
int main() {
    //freopen("F:\\rush.txt", "r", stdin);
    pre[0] = 1;
    rep1(i, 1, 60)
        pre[i] = pre[i - 1] * 2;
    rep1(i, 1, 60) sg[i] = dfs(i, pre[i] - 1);
    rei(n);
    while (n--) {
        int x;
        rei(x);
        ju ^= sg[x];
    }
    if (ju != 0)
        puts("NO");
    else
        puts("YES");
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
【codeforces 768E】Game of Stones的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
		
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
 - 【codeforces 707E】Garlands
		
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
 - 【codeforces 707C】Pythagorean Triples
		
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
 - 【codeforces 709D】Recover the String
		
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
 - 【codeforces 709B】Checkpoints
		
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
 - 【codeforces 709C】Letters Cyclic Shift
		
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
 - 【Codeforces 429D】 Tricky Function
		
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
 - 【Codeforces 670C】 Cinema
		
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
 - 【codeforces 515D】Drazil and Tiles
		
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
 
随机推荐
- 第一章、Tiny4412 U-BOOT移植一 说明【转】
			
本文转载自:http://blog.csdn.net/eshing/article/details/37520291 一.移植前说明: 1. 特别声明:此文档是我的学习文档,里面肯定有错误地方,仅供 ...
 - 使用免费SSL证书让网站支持HTTPS访问
			
参考掘金的文章,掘金的文章最详细. https://juejin.im/post/5a31cbf76fb9a0450b6664ee 先检查是否存在 EPEL 源: # 进入目录检查是否存在 EPEL ...
 - 仪表盘(Speedometer) icon 设计
 - 在chrome里模拟调试微信浏览器
			
开发者模式(下面有配图): 开发者模式/DevTools.More tools/Network conditions/User agent/ Custom/安卓或ios代理配置配置 更改User ag ...
 - Coursera公开课-Machine_learing:编程作业4
			
编程作业: Neural Network Learning 源码上传到gitlab. 对于神经网络的理解也都在源码注释里面了,感兴趣可以看看.
 - [转]Linux命令之iconv
			
转自:http://lorna8023.blog.51cto.com/777608/420313 用途说明 iconv命令是用来转换文件的编码方式的(Convert encoding of given ...
 - React容器组件和展示组件
			
Presentational and Container Components 展示组件 - 只关心它们的样子. - 可能同时包含子级容器组件和展示组件,一般含DOM标签和自定的样式. ...
 - Android 基础知识图谱
			
四大组件 Activity Service BroadcastReceiver ContentProvider Application 常用组件 Fragment RecyclerView WebVi ...
 - VS2013支持多字节
			
使用插件 下载地址:https://www.microsoft.com/zh-cn/search/DownloadResults.aspx?rf=sp&q=mbcs
 - TensorFlow: Could not load requested Qt binding.
			
使用Eclipse 引入tensorflow,出现 Could not load requested Qt binding. 问题 ImportError: Could not load reque ...