HDU3980Paint Chain(尼姆博奕SG)
来源:互联网 发布:淘宝网上如何找货源 编辑:程序博客网 时间:2024/06/07 17:39
Paint Chain
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2051 Accepted Submission(s): 751
Problem Description
Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unable to paint in his turn lose the game. Aekdycoin will take the first move.
Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
Input
First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
Output
For each case, print "Case #idx: " first where idx is the case number start from 1, and the name of the winner.
Sample Input
2 3 1 4 2
Sample Output
Case #1: aekdycoin Case #2: abcdxyzk
题意:一个有n个物品的环,每次必须拿m个,谁没的拿谁就输了,问谁赢。
思路:当第一个人拿了一次之后就变成一条链了,此时用SG函数求解,对于前i(i>.= m)个,我们取连续m个,就是sg(i-m)^sg(n-i),这样递推求解。
整体值等于局部值的亦或。
#include<cstdio>#include<iostream>#include<algorithm>#include<queue>#include<stack>#include<cstring>#include<string>#include<vector>#include<cmath> #include<map>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;typedef long long ll;const int maxn = 2e5+5;const int ff = 0x3f3f3f3f;int n,m;int sg[1005],vis[1005];int getsg(int x){mem(vis,0);for(int j = m;j<= x;j++)vis[sg[j-m]^sg[x-j]] = 1;for(int j = 0;;j++)if(!vis[j]){sg[x] = j;break;}return sg[x];}int main(){int t,cnt = 0;cin>>t;while(t--){scanf("%d %d",&n,&m);if(n< m){printf("Case #%d: abcdxyzk\n",++cnt);continue;}n-= m;mem(sg,-1);for(int i = 0;i<= n;i++)sg[i] = i< m?0:getsg(i);if(sg[n] == 0)printf("Case #%d: aekdycoin\n",++cnt);elseprintf("Case #%d: abcdxyzk\n",++cnt);}return 0;}
阅读全文
0 0
- HDU3980Paint Chain(尼姆博奕SG)
- hdu3980Paint Chain+SG博弈
- hdu3980Paint Chain(SG)
- hdu3980 Paint Chain SG函数
- HDU3980 Paint Chain SG函数
- HDOJ 3980 Paint Chain 博弈 SG函数
- HDU 3980 Paint Chain(博弈 SG)
- HDU 3980 Paint Chain(SG函数)
- hdu 3980 Paint Chain (sg函数 )
- hdu 3980 Paint Chain(SG函数)
- HDU 3980 Paint Chain(SG环链游戏)
- HDU 3980 Paint Chain(博弈论,SG函数)
- sg
- SG
- sg
- hdu3980 Paint Chain------sg 环--链 一排石子分成若干堆
- Chain
- Chain
- CSS3概述
- 11.16课堂笔记、作业以及学习心得
- Servlet
- 判断int非负整数为几位数
- VS中MFC中的文件不能运行
- HDU3980Paint Chain(尼姆博奕SG)
- 记忆网络之在对话系统中的应用
- Linux 利用yum源安装nginx
- java语言程序设计 第十三章 (13.13、13.14、13.15、13.16)
- 大型网站购物车的实现
- mysql 5.7.20 解压版 配置安装
- 苏格拉底 《斐多篇》
- ES6入门第1章:关于ES6
- 静态方法与非静态方法的区别