zoj3599 Game----K倍动态减法游戏
2012-09-16 10:43
260 查看
Game
TimeLimit:3Seconds
MemoryLimit:65536KB
AliceandBoddecidetoplayanewstonegame.AtthebeginningAliceputs
n(n>1)stones(outofNinall)onthetable.AliceandBobremovethestonesinturn.Ateachsteptheplayershouldremovesomenumberofstones.Thenumberofstonestheplayerremovedshouldbeatleastone,andcannotexceed
mtimesofthenumberofstonestheplayerremovedatthelaststep.Theplayerwhoremovesthelaststonewinsthegame.Alicealwaysplaysfirstandofcourseatthefirstturn,shecannotremoveallthestones.Alicewantstoknowhowmanypositive
integersnshecanchoosetowinthegameifbothplayersplayoptimally.
Sinceyou'reanaceprogrammer,Alicewantsyoutohelpher.
T(0<T≤500)indicatingthenumberoftestcases.ThenTtestcasesfollow.
Eachtestcaseisalineof2integersmandN(0<m≤2012,1<
N<231)
ntomakeherwinthegame.
[/code]
TimeLimit:3Seconds
MemoryLimit:65536KB
AliceandBoddecidetoplayanewstonegame.AtthebeginningAliceputs
n(n>1)stones(outofNinall)onthetable.AliceandBobremovethestonesinturn.Ateachsteptheplayershouldremovesomenumberofstones.Thenumberofstonestheplayerremovedshouldbeatleastone,andcannotexceed
mtimesofthenumberofstonestheplayerremovedatthelaststep.Theplayerwhoremovesthelaststonewinsthegame.Alicealwaysplaysfirstandofcourseatthefirstturn,shecannotremoveallthestones.Alicewantstoknowhowmanypositive
integersnshecanchoosetowinthegameifbothplayersplayoptimally.
Sinceyou'reanaceprogrammer,Alicewantsyoutohelpher.
Input
Therearemultipletestcases.ThefirstlineofinputcontainsanintegerT(0<T≤500)indicatingthenumberoftestcases.ThenTtestcasesfollow.
Eachtestcaseisalineof2integersmandN(0<m≤2012,1<
N<231)
Output
ForeachtestcaseoutputthenumberofpositiveintegersAlicecanchooseforntomakeherwinthegame.
SampleInput
3 110 210 310
SampleOutput
6 5 4
注意:要用longlong,数组开太大卡内存~
[code]#include<iostream>
#include<cstdlib>
#include<stdio.h>
usingnamespacestd;
constintN=3000000;
longlonga
,b
;
#defineLLlonglong
intmain()
{
intt,k;
longlongn;
scanf("%d",&t);
while(t--)
{
scanf("%d%lld",&k,&n);
a[0]=b[0]=1;
inti=0,j=0;
while(a[i]<n)
{
i++;
a[i]=b[i-1]+1;
while(a[j+1]*k<a[i])
j++;
if(a[j]*k<a[i])b[i]=b[j]+a[i];
elseb[i]=a[i];
}
LLans;
if(a[i]==n)
ans=(LL)n-i-1;
else
ans=(LL)n-i;
cout<<ans<<endl;
}
}
[/code]
相关文章推荐
- HDU A simple stone game [K倍动态减法游戏]
- hdu2486 hdu2580 poj3922 A simple stone game--K倍动态减法游戏 博弈
- ZOJ 3599 K倍动态减法游戏
- HDU - 2486 A simple stone game k倍动态减法游戏
- 斐波那契博弈-K倍动态减法游戏(Poj-3922 A simple stone game)
- uva 1567 - A simple stone game(K倍动态减法游戏)
- a simple stone game--k倍动态规划减法游戏
- K倍动态减法游戏
- uva 1567 - A simple stone game(K倍动态减法游戏)
- K倍动态减法游戏 HDU 2486&&POJ 3922
- (k倍动态减法游戏)zoj 3599 hdu 2486
- HDU 2486 (HDU 2580, POJ 3922) A simple stone game K倍动态减法游戏
- HDOJ 题目2486 A simple stone game(K倍动态减法游戏,模板)
- K倍动态减法游戏
- 从游戏中得到动态内存数据(汇编+VC 例子:疯狂坦克的X坐标)
- 2012第24周移动游戏动态
- 【BZOJ4372】烁烁的游戏(动态点分治)
- cocos2d-x 游戏中人物动态和剪切图片
- Poj-3922 A simple stone game(博弈,k倍动态减法)
- 游戏中MyBatis的动态SQL语句写法