HDU5945 Fxx and Game (monotone queue)

Source: Internet
Author: User

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&GT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.