La 5059 - Playing With Stones
来源:互联网 发布:plc编程证书 编辑:程序博客网 时间:2024/04/30 06:21
题目:La 5059 - Playing With Stones
思路:SG打表题
数据范围很大,一个一个搜不现实,输出前几项的SG值,发现偶数项按整数递增,而剩下的奇数项又是新的一个这样的一个序列,所以递归一下就ok
// 观察一下前几项#include <cstring>#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <set>using namespace std;set<int>s;const int maxn = 2001;int sg[maxn];int get(){ int i=0; while(s.count(i)) i++; return i;}int main(){ sg[1]=0; for(int i=2;i<maxn;i++) { s.clear(); for(int j=1;j*2<=i;j++) // j为从i中拿走不超过一半的 s.insert(sg[i-j]); sg[i]=get(); } for(int i=0;i<100;i++) cout<<i<<" "<<sg[i]<<endl; return 0;}
// AC 代码#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <cstdio>using namespace std;long long sg(long long n){ if(n&1) return sg(n/2); else return n/2;}int main(){ int t; scanf("%d",&t); while(t--) { int n; long long x; scanf("%d",&n); long long ans=0; while(n--) { scanf("%lld",&x); ans^=sg(x); } if(ans) printf("YES\n"); else printf("NO\n"); } return 0;}
- La 5059 - Playing With Stones
- 【LA 5059】 Playing With Stones|博弈论|SG函数
- UVALive 5059 C Playing With Stones
- LA5059 Playing With Stones
- Nim游戏的一个扩展——51nod 1661 黑板上的游戏+LA 5059 Playing With Stones
- UVA - 1482 Playing With Stones
- UVA1482:Playing With Stones(SG)
- uvalive 5059 Playing With Stones(组合游戏,SG函数)@
- uva 1482 - Playing With Stones(Nim游戏)
- UVALive/LA 5059 Play with Stones 组合游戏/SG定理
- UVA 1482 - Playing With Stones (SG博弈)
- UVA 1482 - Playing With Stones(SG打表规律)
- UESTC 1661 Playing With Stones 博弈打表
- UVA-1482 Playing With Stones(SG函数打表找规律)
- Playing with DataGrid Control
- Playing with ptrace
- Playing with the Stack
- Playing with the Stack
- JavaScript 中的陷阱
- Matlab调用openCL性能评测
- 心态一变人生就变
- 【强档推荐】网球王子高清桌面壁纸
- JRebel安装使用说明
- La 5059 - Playing With Stones
- 求高精度幂
- mybatis中Illegal mix of collations for operation 'like' 错误解决方法
- 指针容器: boost::ptr_vector ptr_container
- IOS成长之路-调用照相机和相册功能
- css 浏览器兼容方案
- 初窥GPFS文件系统
- Winsows Server 2012 Datacenter Evaluation Build 9200数据中心评估版GUI 64bit(许可180天)(单用户使用,非傻瓜式优化部分)
- div css布局总结