hdu 5945 Fxx and game
青年理论计算机科学家Fxx给的学生设计了一款数字游戏。 一开始你将会得到一个数X,每次游戏将给定两个参数x,k,t, 任意时刻你可以对你的数执行下面两个步骤之一: .X=X−i(<=i<=t)。 .若X为k的倍数,X=X/k。 现在Fxx想要你告诉他最少的运行步骤,使X变成1。
设f[x]为x的最小变为1步数
initialize: f[1]=0
equation: f[x]=min{f[x-i](i<=t),f[x/k](if x%k==0)} (x:1~x)
对于求min{f[x-i](i<=t)} 使用单调队列维护区间最小f[x-i]
#include <iostream>
#include <cstring>
#include <cmath>
#include <deque>
using namespace std;
const int N=1e6+;
int f[N],k,t;
deque<int>mn;
int dfs(int x)
{
f[] = ;
mn.clear();
mn.push_back();
int j = ;
for(int i=;i<=x;i++)
{
if(i%k==) f[i]=min(f[i],f[i/k]+);
while(!mn.empty() and i-mn.front() > t) mn.pop_front();
if(!mn.empty() and i-mn.front() <= t)
{
f[i]=min(f[i],f[mn.front()]+);
}
while(!mn.empty() and f[mn.back()] >= f[i]) mn.pop_back();
mn.push_back(i);
}
return f[x];
}
int main()
{
int T;
cin>>T;
while(T--)
{
memset(f,0x3f,sizeof(f));
int x;
cin>>x>>k>>t;
if(k>)
cout<<dfs(x)<<endl;
else cout<<int(ceil(double(x-)/t))<<endl;
}
return ;
}
hdu 5945 Fxx and game的更多相关文章
- hdu 5945 Fxx and game(单调队列优化DP)
题目链接:hdu 5945 Fxx and game 题意: 让你从x走到1的位置,问你最小的步数,给你两种走的方式,1.如果k整除x,那么你可以从x走一步到k.2.你可以从x走到j,j+t<= ...
- hdu 5945 Fxx and game(dp+单调队列! bc#89)
Young theoretical computer scientist Fxx designed a game for his students. In each game, you will ge ...
- HDU 5945 Fxx and game (DP+单调队列)
题意:给定一个 x, k, t,你有两种操作,一种是 x - i (0 <= i <= t),另一种是 x / k (x % k == 0).问你把x变成1需要的最少操作. 析:这肯定是 ...
- HDU 5945 / BestCoder Round #89 1002 Fxx and game 单调队列优化DP
Fxx and game 问题描述 青年理论计算机科学家Fxx给的学生设计了一款数字游戏. 一开始你将会得到一个数\:XX,每次游戏将给定两个参数\:k,tk,t, 任意时刻你可以对你的数执行下面 ...
- 【23.33%】【hdu 5945】Fxx and game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s ...
- Fxx and game hdu 5945 单调队列dp
dfs你怕是要爆炸 考虑dp; 很容易想到 dp[ i ] 表示到 i 时的最少转移步数: 那么: dp[ i ]= min( dp[ i ],dp[ i-j ]+1 ); 其中 i-t<=j& ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- hdu 5944 Fxx and string
\:nn,下标从1开始,第\:i\:i位的字母为\:s_isi,现在Fxx想知道有多少三元组\:(i,j,k)\:(i,j,k)满足下列条件 1.i,j,k\:i,j,k三个数成等比数列 2.s ...
- HDU 5945 维护一个单调队列 dp
Fxx and game Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Tot ...
随机推荐
- Android版本4.0~7.0
Android 4.0 Ice Cream Sandwich(冰激凌三明治):2011年10月19日发布 版本主要更新如下:全新的UI:全新的Chrome Lite浏览器:截图功能:更强大的图片编辑功 ...
- NPOI 2.0版本的使用
详细教程: http://blog.csdn.net/xxs77ch/article/details/50216033 using System; using System.Collections.G ...
- JavaScript 对象的创建和对6种继承模式的理解和遐想
JS中总共有六种继承模式,包括原型链.借用构造函数.组合继承.原型式继承寄生式继承和寄生组合式继承.为了便于理解记忆,我遐想了一个过程,对6中模式进行了简单的阐述. 很长的一个故事,姑且起个名字叫 ...
- Reverse链表 递归实现
#include<iostream> struct node{ int payload; node* next; }; void bianli(node* head){ node* ite ...
- 實際案例: 獲取臨時票証 (JsApi Ticket)
專案中選用大名鼎鼎的 Senparc 微信開發套件 獲取臨時票證處理常式的程式碼 (GetgVXinInfo.ashx) using Senparc.Weixin; using Senparc.Wei ...
- ubuntu locale 语言设置
第一步,编辑文件 代码: sudo gedit /var/lib/locales/supported.d/local 写入相关内容,比如写入如下内容: 代码: zh_CN.UTF-8 UTF-8zh ...
- aspx页面调用发送邮件验证码(结合前两篇)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...
- 一个无缝滚动的jquery插件
$.fn.imgscroll = function(o){ var defaults = { speed: 40, amount: 0, width: 1, dir: "left" ...
- listbox 报错 Cannot have multiple items selected when the SelectionMode is Single.
1.错误提示:Cannot have multiple items selected when the SelectionMode is Single. 刚刚在处理两个Listbox时,将其中一个li ...
- SQL Server Bulk Insert批量数据导入
SQL Server的Bulk Insert语句可以将本地或远程的数据文件批量导入到数据库中,速度非常的快.远程文件必须共享才行,文件路径须使用通用约定(UNC)名称,即"\\服务器名或IP ...