标签:stdin math std out cond 题解 sdi getc line
题意:
给你三个数x,k,t(1e6),表示你在x每次可以减1-t或者可以整除k的时候除以k
问你到达1的最小步数
思路:
这次BC简直福利场。。过了题就上分
我是用单调队列维护的前k个值,然后被卡掉了- -
看了题解改成单调队列维护,当时就没想到啊(其实是以为不会被卡就没改而已)
/* *********************************************** Author :devil ************************************************ */ #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> #define LL long long #define rep(i,a,b) for(int i=a;i<=b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define ou(a) printf("%d\n",a) #define pb push_back #define mkp make_pair template<class T>inline void rd(T &x) { char c=getchar(); x=0; while(!isdigit(c))c=getchar(); while(isdigit(c)) { x=x*10+c-‘0‘; c=getchar(); } } #define IN freopen("in.txt","r",stdin); #define OUT freopen("out.txt","w",stdout); using namespace std; const int inf=0x3f3f3f3f; const int mod=1e9+7; const int N=1e6+10; pair<int,int> dp[N]; int f[N],t,x,k,v; int main() { #ifndef ONLINE_JUDGE //IN #endif scanf("%d",&t); while(t--) { scanf("%d%d%d",&x,&k,&v); int l=0,r=0; for(int i=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; }
标签:stdin math std out cond 题解 sdi getc line
原文地址:http://www.cnblogs.com/d-e-v-i-l/p/6012822.html