HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)
A simple stone game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 312 Accepted Submission(s): 167
The game goes like this: Two players start the game with a pile of n stones. They take stones from the pile in turn and every time they take at least one stone. The one who goes first can take at most n-1 stones for his first move. From then on a player can take at most k times as many stones as his opponent has taken last time. For example, if one player take m stones in his turn, then the other player can take at most k × m stones next time. The player who takes the last stone wins the game. Suppose that those two players always take the best moves and never make mistakes, your job is to find out who will definitely win the game.
Each test case is a line consisting of two integer n and k.(2<=n<=10^8,1<=k<=10^5).




#include<stdio.h>
#define maxn 1000000
int n , k ; int a[maxn+];
int r[maxn+];
void solve()
{
int i,j;
a[]=a[]=;
for(i=,j= ;i<=maxn;i++)
{
a[i]=r[i-]+;
while(j+<i && a[j+]*k<a[i])
j++;
r[i]=a[i]+r[j];
if(r[i]>=n) break;
}
if(i>maxn)
{
printf("un solvable\n");
return ;
}
if(a[i]==n)
{
printf("lose\n");
return ;
}
for( ; i>= ;i--)
{
if(n==a[i])
{
printf("%d\n",n);
return ;
}
else if(n>a[i]) n-=a[i];
}
printf("logic error\n");
}
int main()
{
int ca ,cc=;
scanf("%d",&ca);
while(ca-->)
{
scanf("%d %d",&n,&k);
printf("Case %d: ",++ cc);
solve();
}
return ;
}
HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)的更多相关文章
- 尼姆博弈扩展形式(一): 限定每次取物的上限。NYOJ-135,难度5~~~
取石子(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:5 http://acm.nyist.net/JudgeOnline/problem.php?pid=135 描述 小 ...
- Being a Good Boy in Spring Festival 尼姆博弈
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- LightOJ 1247 Matrix Game (尼姆博弈)
A - Matrix Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...
- Light OJ 1253 Misere Nim (尼姆博弈(2))
LightOJ1253 :Misere Nim 时间限制:1000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 Alice and Bob ar ...
- POJ 2234 Matches Game (尼姆博弈)
题目链接: https://cn.vjudge.net/problem/POJ-2234 题目描述: Here is a simple game. In this game, there are se ...
- codeforces - 15C Industrial Nim(位运算+尼姆博弈)
C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1849(Rabbit and Grass) 尼姆博弈
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
Climbing the Hill Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Su ...
随机推荐
- 【原创】pads layout 画多边形copper,出现Self-Intersecting Polygon,解决办法
在做线性位移传感器的电路板时,需要在一个很小的多边形Copper操作,总是提示“Self-Intersecting Polygon”报错,意思是outline线自身交叉,换句话说就是线宽与多边形尺寸没 ...
- [SAP ABAP开发技术总结]列表屏幕
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- JS学习笔记(四) 正则表达式(RegExp对象)
参考资料: 1. http://www.w3school.com.cn/js/js_obj_regexp.asp ☂ 知识点: ☞ RegExp是正则表达式的缩写. ☞ RegExp是一种模式,用于在 ...
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- 如何在VirtualBox虚拟机软件上安装Win7虚拟系统
在Windows系统中安装VirtualBox 双击从官网上下载的VirtualBox-4.3.12-93733-Win.exe安装程序,默认下一步,下一步完成基础安装. 在VirtualBox虚拟机 ...
- netbeans环境的建立
这是一个简单的实验,熟悉NetBeans的IDE环境的开发 首先下载一个NetBeans,可以在官网上下https://netbeans.org/downloads/index.html 要装NetB ...
- 泰信---->20131025~20131101(周计划安排)
学习java相关知识计划安排: [前期复习阶段] (一)熟悉java相关语言基础. (二)搭建一个纯web项目工程,实现增加,删除,修改,查询以及分页...功能. (三)熟悉jboss的使用和相关配置 ...
- shell script的连接符是逗号,不是英文的句号
举个例子: gawk 'BEGIN{ var[ var[ var[ var[ asort(var,test) for(i in test) print ] }' 这时候敲回车就能输出 Index: - ...
- iOS - XML 数据解析
前言 @interface NSXMLParser : NSObject public class NSXMLParser : NSObject 1.XML 数据 XML(Extensible Mar ...
- c++ 复习练习
复习c++的时候,发现一篇 如何通过c++ primer学习c++的好文,并列出了一些建议的练习题目. 链接,http://blog.csdn.net/solstice/article/details ...