La 5059 - Playing With Stones
2013-09-08 16:24
316 查看
题目:La 5059 - Playing With Stones
思路:SG打表题
数据范围很大,一个一个搜不现实,输出前几项的SG值,发现偶数项按整数递增,而剩下的奇数项又是新的一个这样的一个序列,所以递归一下就ok
思路: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|博弈论|SG函数
- LA 5059 - Playing With Stones
- LA 5059 (找规律 SG函数) Playing With Stones
- UVaLive5059 Playing With Stones
- UVALive 5059 C Playing With Stones
- Nim游戏的一个扩展——51nod 1661 黑板上的游戏+LA 5059 Playing With Stones
- UVALive 5059 C - Playing With Stones 博弈论Sg函数
- UESTC 1661 Playing With Stones 博弈打表
- uva 1482 - Playing With Stones
- UVA1482:Playing With Stones(SG)
- LA5059 Playing With Stones
- LA5059 Playing With Stones
- LA5059 Playing With Stones
- UVA - 1482 Playing With Stones
- UVALive/LA 5059 Play with Stones 组合游戏/SG定理
- UVa 10067 - Playing with Wheels
- Playing with Numbers Kattis - playingwithnumbers GCD LCM
- Some R functions while playing with the table
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
- Playing with Paper