K倍动态减法游戏!!!
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4683
代码如下:
1 #include<iostream> 2 #include<cstdlib> 3 #include<stdio.h> 4 #define ll long long 5 using namespace std; 6 ll a[3000000],b[3000000]; 7 int main() 8 { 9 int i,j,t,k; 10 ll n,ans; 11 scanf("%d",&t); 12 while(t--){ 13 scanf("%d%lld",&k,&n); 14 i=j=0; 15 a[0]=b[0]=1; 16 while(a[i]<n){ 17 i++; 18 a[i]=b[i-1]+1; 19 while(a[j+1]*k<a[i]) j++; 20 if(a[j]*k<a[i]) b[i]=b[j]+a[i]; 21 else b[i]=a[i]; 22 } 23 if(a[i]==n) ans=(ll)n-i-1; 24 else ans=(ll)n-i; 25 printf("%lld ",ans); 26 } 27 return 0; 28 }