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 ...
随机推荐
- Exception in thread java.lang.IllegalThreadStateException
比较好理解的抛出:非法线程状态抛出 出现这个问题的原因是: 对一个状态为RUNNABLE的线程再次调用start()方法,或者对一个状态为TERMINATED再次调用start()方法. 总之,在线程 ...
- Examples For When-Validate-Item trigger In Oracle Forms
The following example finds the commission plan in the COMMPLAN table, based on the current value of ...
- MySQL性能优化的21个最佳实践 和 mysql使用索引
1. 为查询缓存优化查询 当有很多相同的查询被执行了多次的时候,这些查询结果会被放到一个缓存中,这样,后续的相同的查询就不用操作表而直接访问缓存结果了. 2. EXPLAIN SELECT 查询 ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- intanceof以及引出的__proto__和prototype
instanceof运算代码 function instance_of(L, R) { //L 表示左表达式,R 表示右表达式 var O = R.prototype; // 取 R 的显示原型 L ...
- MongoDB 中遇到的一些错误
1.在win平台上,使用ctrl+c关闭mongodb后,使用 mongod --dbpath=D:\mongodb\db --logpath=D:\mongodb\log.txt --port -- ...
- iOS - MVP 架构模式
1.MVP 从字面意思来理解,MVP 即 Modal View Presenter(模型 视图 协调器),MVP 实现了 Cocoa 的 MVC 的愿景.MVP 的协调器 Presenter 并没有对 ...
- oracle学习之bulk collect用法
通过bulk collect减少loop处理的开销,使用Bulk Collect提高Oracle查询效率 Oracle8i中首次引入了Bulk Collect特性,该特性可以让我们在PL/SQL中能使 ...
- MySql 去重且指定某字段在前的排序方法
今天遇到一个棘手的数据查找并去重的问题: 情况: 1.取出数据库中的数据: 2.同一字段A,不同情况<值,如A值为:a1,a2>下取出的其他数据可能相同: 3.将2情况下的重复数据< ...
- poj2540Hotter Colder(半平面交)
链接 根据距离可以列得直线方程,附上初始矩形的四个顶点,依次用直线切割. #include<iostream> #include <stdio.h> #include < ...