Paint Chain

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 804    Accepted Submission(s): 292

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.

 
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
 
Author
jayi
 
Source

题意:有一圈 N 个的硬币, 两个玩家轮流取,每次他们可以取M个连续硬币, 最后一个不能取的为负;

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,m,sg[N]; int mex(int x){
if(sg[x]!=-)
return sg[x];
int re[N];
memset(re,,sizeof(re));
for(int i=;i<=x-m-i;i++)
re[mex(i)^mex(x-m-i)]=;
int i=;
while(re[i]!=)
i++;
return sg[x]=i;
} int main(){ //freopen("input.txt","r",stdin); int t,cases=;
scanf("%d",&t);
while(t--){
memset(sg,-,sizeof(sg));
printf("Case #%d: ",++cases);
scanf("%d%d",&n,&m);
if(n<m){
puts("abcdxyzk");
continue;
}
if(m==){
if(n&)
puts("aekdycoin");
else
puts("abcdxyzk");
continue;
}
if(!mex(n-m))
puts("aekdycoin");
else
puts("abcdxyzk");
}
return ;
}

HDU 3980 Paint Chain (sg函数)的更多相关文章

  1. hdu 3980 Paint Chain sg函数

    题目链接 给一个长度为n的环, 两个人轮流涂色, 每次涂m个连续的, 无法继续涂了就输. #include<bits/stdc++.h> using namespace std; #def ...

  2. hdu 3980 Paint Chain 组合游戏 SG函数

    题目链接 题意 有一个\(n\)个珠子的环,两人轮流给环上的珠子涂色.规定每次涂色必须涂连续的\(m\)颗珠子,无法继续操作的人输.问先手能否赢. 思路 参考 转化 第一个人取完之后就变成了一条链,现 ...

  3. HDU - 3980 Paint Chain(SG函数)

    https://vjudge.net/problem/HDU-3980 题意 一串长度为n的柱子,每个人只能给连续的珠子涂色,涂过的不能再涂,不能涂的人就输了,问最后谁获胜. 分析 第一个人先涂m个, ...

  4. HDU 3970 Paint Chain (博弈,SG函数)

    Paint Chain Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

  6. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

  7. hdu 1079 Calendar Game sg函数 难度:0

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 5724 Chess(SG函数)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  9. HDU 1535 S-Nim(SG函数)

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

随机推荐

  1. 从头来之【iOS及历史版本特性介绍】

    iOS是apple公司的移动操作系统,在iPhone,iPad,iPod中应用,该名最初为Cisco的网络设备操作系统,后授权于Apple公司使用.下面介绍历史版本的特性. iOS1 最大特性是具有其 ...

  2. Google想出了一个决定人员晋升的算法,然后就没有然后了......

    Google 有点跑偏了,逗死我了~实践一下也好~ Prasad Setty 是 Google People Analytics 团队的副总裁.7 年前 Google 成立的这支团队的职责是收集和利用 ...

  3. tomcat中的日志开关文件(logging.properties)介绍

    以tomcat-6.0.29为例: http://www.ossez.com/thread-18138-1-1.html #配置tomcat的日志输出方式,这里表示文件输出和控制台输出.handler ...

  4. PHP http_build_query()方法

    http_build_query (PHP 5) http_build_query -- 生成 url-encoded 之后的请求字符串描述 string http_build_query ( arr ...

  5. Android studio 将 Module 打包成 Jar 包

    整理记录 AndroidStudio 把一个 module 项目打包成 jar 包. 一.默认自动生成的 jar 包 众所周知 android studio 会在library所依赖的 app运行 或 ...

  6. 【树莓派】树莓派刷Android系统

    树莓派3安装Android TV系统图文教程 http://www.mz6.net/news/android/6866.html 树莓派3 Android TV系统怎样安装?树莓派3一个重要用途就是当 ...

  7. Nginx反向代理转发Host设置

    默认情况下反向代理是不会转发请求中的Host头部,如果需要转发,则需要配置红色字体表示的选项参数. location /t02 { proxy_set_header Host $host; proxy ...

  8. 安装 mysql-5.6.4-m7

    1.首先下载:http://cdn1.mydown.yesky.com/soft/201403/mysql-5.6.4-m7.tar.gz 2.解压,进入目录,执行cmake ./(如果没有cmake ...

  9. JAVA各种泛型事例总结

    转自:http://www.cnblogs.com/sunwei2012/archive/2010/10/08/1845938.html 普通泛型 class Point<T>{ // 此 ...

  10. Mahout 协同过滤 itemBase RecommenderJob源码分析

    来自:http://blog.csdn.net/heyutao007/article/details/8612906 Mahout支持2种 M/R 的jobs实现itemBase的协同过滤 I.Ite ...