Fxx and game

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 688    Accepted Submission(s): 162

Problem Description
Young theoretical computer scientist Fxx designed a game for his students.

In each game, you will get three integers X,k,t

.In each step, you can only do one of the following moves:

1.X=X−i(0<=i<=t)

.

2.

if k|X,X=X/k

.

Now Fxx wants you to tell him the minimum steps to make X

become 1.

 
Input
In the first line, there is an integer T(1≤T≤20)

indicating the number of test cases.

As for the following T

lines, each line contains three integers X,k,t(0≤t≤106,1≤X,k≤106)

For each text case,we assure that it's possible to make X

become 1。

 
Output
For each test case, output the answer.
 
Sample Input
2
9 2 1
11 3 3
 
Sample Output
4
3
 
Source
题意:给你三个数x,k,t 有两种操作 1.X=X−i(0<=i<=t) .2. if k|X,X=X/k . 问最少经过多少步使得x->1
题解:维护一个变换次数递增的单调队列
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int cas;
int x,k,t,l,r;
int d[];
int dis[];
int main()
{
scanf("%d",&cas);
for(int i=; i<=cas; i++)
{
scanf("%d %d %d",&x,&k,&t);
l=r=;
d[]=;
for(int j=;j<=x;j++) dis[j]=INF;
dis[]=;
for(int j=; j<=x; j++)
{
while(l<=r&&d[l]<j-t) l++;//把队列中没有用的点去掉
if(l<=r) dis[j]=dis[d[l]]+;
if(j%k==) dis[j]=min(dis[j],dis[j/k]+);
while(l<=r&&dis[d[r]]>=dis[j])r--;//将队列中变换次数多的去掉
d[++r]=j;
}
printf("%d\n",dis[x]);
}
return ;
}

HDU 5945 维护一个单调队列 dp的更多相关文章

  1. 【CSP-S 2019】【洛谷P5665】划分【单调队列dp】

    前言 \(csp\)时发现自己做过类似这道题的题目 : P4954 [USACO09Open] Tower of Hay 干草塔 然后回忆了差不多\(15min\)才想出来... 然后就敲了\(88p ...

  2. [CSP-S模拟测试]:Cover(单调栈++单调队列+DP)

    题目传送门(内部题126) 输入格式 第一行两个个整数$n,m$表示区间的长度与彩灯的数量. 接下来$m$行,每行三个整数$l_i,r_i,a_i$表示一条彩灯能够覆盖的区间以及它的美观程度. 输出格 ...

  3. bzoj 1012 维护一个单调数列

    Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...

  4. poj2373 Dividing the Path (单调队列+dp)

    题意:给一个长度为L的线段,把它分成一些份,其中每份的长度∈[2A,2B]且为偶数,而且不能在某一些区间内部切开,求最小要分成几份 设f[i]为在i处切一刀,前面的满足要求的最小份数,则f[L]为答案 ...

  5. BZOJ1855 [Scoi2010]股票交易[单调队列dp]

    题 题面有点复杂,不概括了. 后面的状态有前面的最优解获得大致方向是dp.先是瞎想了个$f[i][j]$表示第$i$天手里有$j$张股票时最大收入(当天无所谓买不买). 然后写了一个$O(n^4)$状 ...

  6. 刷题总结——烽火传递(单调队列+dp)

    题目: 题目描述 烽火台又称烽燧,是重要的防御设施,一般建在险要处或交通要道上.一旦有敌情发生,白天燃烧柴草,通过浓烟表达信息:夜晚燃烧干柴,以火光传递军情.在某两座城市之间有 n 个烽火台,每个烽火 ...

  7. 1304F2 - Animal Observation (hard version) 线段树or单调队列 +DP

    1304F2 - Animal Observation (hard version) 线段树or单调队列 +DP 题意 用摄像机观察动物,有两个摄像机,一个可以放在奇数天,一个可以放在偶数天.摄像机在 ...

  8. POJ 3017 单调队列dp

    Cut the Sequence Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8764   Accepted: 2576 ...

  9. UVA 1619/POJ2796 滑窗算法/维护一个单调栈

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12409   Accepted: 3484 Case T ...

随机推荐

  1. Jquery API Hybrid APP调研

    http://jquery.cuishifeng.cn/source.html   hybrid app Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间 ...

  2. C# 正则表达式 验证:数字、带小数点数字、电话和手机

    一.带小数点数字 public static bool IsNumber(string input) { string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\ ...

  3. wp8.1 Study10:APP数据存储

    一.理论 1.App的各种数据在WP哪里的? 下图很好介绍了这个问题.有InstalltionFolder, knownFolder, SD Card... 2.一个App的数据存储概览 主要分两大部 ...

  4. 自定义圆的半径layout

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:too ...

  5. 100个iOS开发/设计面试题汇总

    常见问题 你昨天/这周学习了什么? 你为什么热衷于软件开发? 你对哪一种控制系统比较熟悉? 是否参与过GitHub项目? 是否参与过GitHub或其他同类型网站的iOS开源项目? 请描述一下你的iOS ...

  6. 微软.NET Framework 4.5.2 RTM正式版

    今天,微软.NET开发团队发布.NET Framework 4.5.2 RTM正式版.新版框架继续高度兼容现有的.NET Framework 4.4.5.4.5.1等版本,该版本框架与旧版的.NET ...

  7. NSURLSession使用实战教程

    我的前面两篇文章介绍了NSURLSession套件的使用和NSURLSession套件的主要类.今天我们使用NSURLSession来完成一个小的应用程序.在实战之前,我先补充一点,为什么苹果会主推N ...

  8. 《java版进制转换》

    import java.util.Scanner; class 十进制转成十六进制_2 { public static void main(String[] args) { int num = 0; ...

  9. PAT 05-树8 Huffman Codes

    以现在的生产力,是做不到一天一篇博客了.这题给我难得不行了,花了两天时间在PAT上还有测试点1没过,先写上吧.记录几个做题中的难点:1.本来比较WPL那块我是想用一个函数实现的,无奈我对传字符串数组无 ...

  10. 找不到库文件地址,修改修改方法framework

    直接双击地址行修改