51nod-1714 B君的游戏
来源:互联网 发布:lol域名不能备案 编辑:程序博客网 时间:2024/05/16 14:22
原题链接
1714B君的游戏
基准时间限制:1 秒 空间限制:131072 KB 分值:40难度:4级算法题
B君和L君要玩一个游戏。刚开始有n个正整数 a i 。
双方轮流操作。每次操作,选一个正整数x,将其移除,再添加7个数字x 1 ,x 2 ...x 7 。要求对于 x i ,满足 0<=x i <x 且 x&x i =x i
注意0不能被选取,所以这个游戏一定会结束,而谁无法操作谁就失败。
B君根据自己的经验,认为先手胜率高一点,所以B君是先手。
B君想知道自己是否必胜。
双方轮流操作。每次操作,选一个正整数x,将其移除,再添加7个数字
注意0不能被选取,所以这个游戏一定会结束,而谁无法操作谁就失败。
B君根据自己的经验,认为先手胜率高一点,所以B君是先手。
B君想知道自己是否必胜。
Input
第一行一个整数n (1 <= n <= 100000)以下n行n个数ai (0 <= a_i < 2^64)
Output
如果先手必胜,输出"B",否则输出"L"。
Input示例
41234
Output示例
B
注意到每个数的SG值,只和其中有多少个1有关。SG[i]是数x包含i个1的时候的SG值。然后,直接异或起来所有SG值即可。
用了158.1s算出所有sg值
#include<iostream>#include<cstdlib>#include<cstdio>#include<vector>#include<cstring>#define maxn 70000000using namespace std;typedef long long LL;int sg[65], maxs;int cnt[maxn];void dfs(int j, int m, int ans, int v){if(m == 0){ maxs = ans > maxs ? ans : maxs;cnt[ans] = 1;return ;}for(int i = v; i < j; i++){dfs(j, m-1, ans^sg[i], i);}}void Init(){sg[0] = 0;for(int i = 1; i <= 64; i++){for(int h = 0; h <= maxs; h++) cnt[h] = 0;maxs = 0;dfs(i, 7, 0, 0);for(int j = 0; j < maxn; j++){if(cnt[j] == 0){sg[i] = j;break;}} printf("%d\n", sg[i]);}}int main(){Init();}
对输入的数算出其包含几个1,然后用sg值异或
#include<iostream>#include<cstdlib>#include<cstdio>#include<vector>#include<cstring>using namespace std;typedef unsigned long long ull;int sg[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 255, 256, 512, 1024, 2048, 3855, 4096, 8192, 13107, 16384, 21845, 27306, 32768, 38506, 65536, 71576, 92115, 101470, 131072, 138406, 172589, 240014, 262144, 272069, 380556, 524288, 536169, 679601, 847140, 1048576, 1072054, 1258879, 1397519, 2005450, 2097152, 2121415, 2496892, 2738813, 3993667, 4194304, 4241896, 4617503, 5821704, 7559873, 8388608, 8439273, 8861366, 11119275, 11973252, 13280789, 16777216, 16844349, 17102035, 19984054, 21979742, 23734709};int main(){//freopen("in.txt", "r", stdin);int n;while(scanf("%d", &n) == 1){ull ans = 0, a;for(int i = 0; i < n; i++){scanf("%Iu64d\n", &a);int h = 0;ull d = 1;for(int i = 0; i <= 63; i++){if((d<<i)&a) h++;}ans ^= sg[h];}if(ans == 0) puts("L");else puts("B");}return 0;}
0 0
- 51nod-1714 B君的游戏
- 51nod 1714 B君的游戏
- 51Nod-1714-B君的游戏
- 51nod 1714 B君的游戏
- 51nod 1714 B君的游戏
- 51nod 1714-B君的游戏(尼姆博弈)
- 51NOD 算法马拉松15(脱欧专场) B君的游戏(博弈)
- 51NOD 1629 B君的圆锥
- 51nod B君的圆锥
- 51nod 1632 B君的连通
- 51nod-【1629 B君的圆锥】
- 51Nod 1629 B君的圆锥
- 51nod 1629 B君的圆锥
- 51nod-1632B君的连通
- 51Nod 1629 B君的圆锥
- 51nod 1630 B君的竞技场
- 51Nod-1630-B君的竞技场
- 51nod 1629 B君的圆锥
- Oracle 大数据集成实施
- JS强制类型转换
- Python3.4中filter函数,map函数和reduce函数
- HDU 1242 - Rescue(BFS+优先队列)
- BestCoder Round #86题解报告
- 51nod-1714 B君的游戏
- Manacher算法(最长回文串)
- CSS—position
- linux中安装gcc和g++
- C#入门6.18——本章总结及任务实施
- 背包小析
- Wireshark入门与进阶系列十一之SSL分析
- jS历史
- 《如何在WordPress上添加微信/支付宝打赏功能》