Codeforces 768E Game of Stones 博弈SG(打表)
来源:互联网 发布:软件构架实践 pdf 编辑:程序博客网 时间:2024/05/16 18:31
点击打开链接
题意:n堆stone,每堆s[i]个 s[i]<=60,n<=1e6,若从第i堆拿了x个 则第i堆不能再取x个,无法操作则输
找到i个石头的SG值,同样i个,取的石头可能有不同的限制.设dp[i][j] i表示石子数量 j表示能取的状态的SG值 O(n*2^n*logn)
最终游戏要求的异或和为:dp[i][2^i-1](i=1~n) 打表找到dp[i](2^i-1)规律即可
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,ll> ii;const int M=2e6+20;const int N=70;map<pair<int,ll>,int> grundy;map<pair<int,ll>,bool> mp;int Grundy(int i,ll j){if(mp[ii(i,j)])//该状态grundy已经被计算 return grundy[ii(i,j)];vector<bool> mk(63,false);for(int k=0;k<i;k++)//取k+1个 {if(((j>>k)&1)==0)//状态j第k位为0,不能取k+1个 continue;mk[Grundy((i-k-1ll),(j^(1ll<<k)))]=true;}int ret;for(int k=0;k<63;k++){if(mk[k]==false){grundy[ii(i,j)]=k;ret=k;break;}}mp[ii(i,j)]=true;return ret;}void calc(){grundy[ii(0,0)]=0;mp[ii(0,0)]=true;vector<int> gr(70,0);for(int i=0;i<=60;i++)gr[i]=Grundy(i,(1ll<<i)-1ll),cout<<gr[i]<<' ';}int f[N];int main(){//calc();//规律 2个1,3个2,4个3.(n+1)个n int i=0,cnt=0;while(i<=60){for(int k=0;k<=cnt;k++)f[i++]=cnt;cnt++;}int n;while(cin>>n){int x,ans=0;for(int i=0;i<n;i++){scanf("%d",&x);ans=ans^f[x];}if(ans==0)puts("YES");//后手winelseputs("NO"); }return 0;}
0 0
- Codeforces 768E Game of Stones 博弈SG(打表)
- Codeforces 768E Game of Stones 博弈
- codeforces 768 E Game of Stones(博弈)
- CodeForces 768E Game of Stones (Nim博弈)
- codeforces 399 E. Game of Stones 博弈 思维题
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces 768E Game of Stones
- 768E Game of Stones[Nim游戏][博弈]
- Codeforces Round #399:E. Game of Stones
- codeforces 786E Game of Stones
- HDU 1846 Brave Game 巴什博弈 SG打表
- BZOJ_P1228 [SDOI2009]E&D(博弈+SG函数+打表)
- HDU 5973 Game of Taking Stones 博弈+高精度
- ZOJ 3964 Yet Another Game of Stones (博弈)
- Game of Taking Stones (大数 + 威佐夫博弈 java写的)
- HDU5973 Game of Taking Stones (大数博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- ZOj 3964Yet Another Game of Stones(nim博弈)
- 正则表达式的方法--re
- vi笔记
- perl发邮件附件乱码问题
- GPIO的配置过程
- react+webpack构建步骤
- Codeforces 768E Game of Stones 博弈SG(打表)
- Java反射机制详解
- 【转载】stm32中断学习
- [李景山php] 深入理解PHP内核[读书笔记]--第二章:用户代码执行--SAPI概述
- 图片
- 一点反思
- caffe常用的cblas函数
- 施恩难忘
- 对GPIO_Init(GPIOx,&GPIO_InitStructure)的理解