hdu3980 Paint Chain
来源:互联网 发布:拼人脸五官的软件 编辑:程序博客网 时间:2024/06/05 09:04
Paint Chain
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 897 Accepted Submission(s): 316
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这题 要注意,如果,刚开始,总个数少于M个,那么就直接输掉,然后再解环成链,只能有一种选择,这种情况之下,就只能求出sg函数值,且先手与后手,已经交换了!#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#pragma comment(linker,"/STACK:1024000000,1024000000")#define M 1050#define mem(a,b) memset(a,b,sizeof(a))int dp[M],m;int getsg(int n){ if(dp[n]!=-1)return dp[n]; if(n<m)return dp[n]=0; int i;bool vis[M]; mem(vis,0); for(i=0;i<=n-m;i++){ if(dp[i]==-1)dp[i]=getsg(i); if(dp[n-i-m]==-1)dp[n-i-m]=getsg(n-i-m); vis[dp[i]^dp[n-i-m]]=1; } for(i=0;;i++) if(!vis[i]) return i;}int main(){ int tcase,tt=1,n; scanf("%d",&tcase); while(tcase--){ scanf("%d%d",&n,&m); mem(dp,-1); printf("Case #%d: ",tt++); int ans=0; if(n>=m)ans=getsg(n-m)?0:1; if(ans) printf("aekdycoin\n"); else printf("abcdxyzk\n"); } return 0;}
- hdu3980 Paint Chain
- hdu3980 Paint Chain 组合nim
- hdu3980 Paint Chain SG函数
- HDU3980 Paint Chain SG函数
- hdu3980 Paint Chain------sg 环--链 一排石子分成若干堆
- hdu3980
- hdu 3980. Paint Chain
- HDU 3980 Paint Chain
- hdu 3980 Paint Chain
- Hdu 2980Paint Chain(博弈论)
- hdoj 3980 Paint Chain(数学推导)
- HDOJ 3980 Paint Chain 博弈 SG函数
- HDU 3980 Paint Chain(尼姆博弈)
- 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环链游戏)
- Windows Socket programming 2
- hdu4292 Food (ISAP算法)
- Android简单、快速的网络库: Volley ( Google IO 2013 )
- Java工具类之Pattern和Matcher(一)
- VC++实现简单HTTP服务器
- hdu3980 Paint Chain
- C/C++ 程序设计员应聘常见面试试题
- 2013 ACM/ICPC Asia Regional Changchun Online (2013网络赛)
- 因此我们并不知道“小道消息”的微信账号到底有多少追随
- linux sar 命令详解
- 数字图像处理(一) matlab图像简单操作
- Fix for "convert: no decode delegate for this image format"
- A Funny Game
- Java工具类之StringBuffer