Test instructions
Give you three numbers x,k,t (1e6), which means you divide by K when X can be reduced by 1-t or divisible by K.
Ask you the minimum number of steps to reach 1
Ideas:
This BC is simply a welfare field. After the problem, the score
I was the first k value maintained in a monotone queue, and then I got stuck out--
Read the fix to a monotonous queue maintenance, then did not think AH (in fact, I think it will not be the card to change it)
/************************************************author:d evil*********************************************** * */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<stack>#include<map>#include<string>#include<time.h>#include<cmath>#include<stdlib.h>#defineLL Long Long#defineRep (i,a,b) for (int i=a;i<=b;i++)#defineDEP (I,A,B) for (int i=a;i>=b;i--)#defineOU (a) printf ("%d\n", a)#definePB Push_back#defineMKP Make_pairTemplate<classT>inlinevoidRD (T &x) { CharC=GetChar (); X=0; while(!isdigit (c)) c=GetChar (); while(IsDigit (c)) {x=x*Ten+c-'0'; C=GetChar (); }}#defineIn Freopen ("In.txt", "R", stdin);#defineOut Freopen ("OUT.txt", "w", stdout);using namespacestd;Const intinf=0x3f3f3f3f;Const intmod=1e9+7;Const intn=1e6+Ten;p Air<int,int>Dp[n];intf[n],t,x,k,v;intMain () {#ifndef Online_judge//inch#endifscanf ("%d",&t); while(t--) {scanf ("%d%d%d",&x,&k,&v); intL=0, r=0; for(intI=2; i<=x;i++) { if(i<=v+1) {F[i]=1; Dp[r].first=i,dp[r++].second=1; Continue; } while(I-DP[L].FIRST>V) l++; F[i]=dp[l].second+1; if(i%k==0) F[i]=min (f[i],f[i/k]+1); while(r>l&&f[i]<dp[r-1].second) r--; Dp[r].first=i,dp[r++].second=F[i]; } printf ("%d\n", f[x]); } return 0;}
HDU5945 Fxx and Game (monotone queue)