hdu - 5945 Fxx and game 【dp + 单调队列】
来源:互联网 发布:sql执行顺序 编辑:程序博客网 时间:2024/05/25 05:37
Fxx and game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 413 Accepted Submission(s): 100
Problem Description
Young theoretical computer scientist Fxx designed a game for his students.
In each game, you will get three integersX,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 makeX become 1.
In each game, you will get three integers
Now Fxx wants you to tell him the minimum steps to make
Input
In the first line, there is an integer T(1≤T≤20) indicating the number of test cases.
As for the followingT 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 makeX become 1。
As for the following
For each text case,we assure that it's possible to make
Output
For each test case, output the answer.
Sample Input
29 2 111 3 3
Sample Output
43
Source
BestCoder Round #89
#include <map>#include <set>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <iostream>#include <stack>#include <cmath>#include <string>#include <vector>#include <cstdlib>//#include <bits/stdc++.h>//#define LOACL#define space " "using namespace std;typedef long long LL;//typedef __int64 Int;typedef pair<int, int> paii;const int INF = 0x3f3f3f3f;const double ESP = 1e-5;const double PI = acos(-1.0);const LL MOD = 1e9 + 7;const int MAXN = 1e6 + 10;int dp[MAXN], que[MAXN], loc[MAXN];int X, k, t;int main() {int T;scanf("%d", &T);while (T--) {scanf("%d%d%d", &X, &k, &t);dp[1] = 0; dp[0] = INF;int tail = 1, head = 1;que[head] = 0; loc[head] = 1;for (int i = 2; i <= X; i++) {dp[i] = INF;if (i%k == 0) dp[i] = dp[i/k] + 1;//找出队顶while (head <= tail && i - t > loc[head]) head++;dp[i] = min(dp[i], que[head] + 1);//新元素加入到队列while (head <= tail && dp[i] < que[tail]) tail--;que[++tail] = dp[i]; loc[tail] = i;}printf("%d\n", dp[X]);}return 0;}
0 0
- hdu 5945 Fxx and Game dp(单调队列优化)
- 【HDU 5945】 Fxx and game 【单调队列优化dp】
- [hdu 5945 Fxx and game] dp+单调队列
- hdu 5945 Fxx and game (dp+单调队列)
- hdu - 5945 Fxx and game 【dp + 单调队列】
- hdu 5945 Fxx and game【dp+单调队列】
- [hdu 5945 Fxx and game] dp+单调队列
- BestCoderRound#89 HDU 5945 Fxx and game【单调队列+DP】
- HDU 5945 Fxx and game [单调队列+dp]【动态规划】
- 【HDU 5945】Fxx and game(DP+单调队列)
- hdu 5945 Fxx and game(dp+单调队列)
- HDU 5945 Fxx and game(DP+单调队列)
- HDU-5945 Fxx and game (dp+单调队列)
- HDU 5945 Fxx and game 单调队列优化DP
- HDU 5945 Fxx and game(dp+单调队列优化)
- HDU 5945 Fxx and game (DP+单调队列优化)
- hdu 5945 Fxx and game(单调队列,dp)
- 【HDU 5945 Fxx and game】+ 单调队列
- 选择排序
- Solr分布式索引SolrCloud原理总结
- Git笔记
- scp命令
- Docker 使用指南 (三)—— 网络配置
- hdu - 5945 Fxx and game 【dp + 单调队列】
- BFS+DFS---简介与模板
- 说下入职IT小公司的感想
- *[Lintcode]Perfect Square
- 12-内部类
- tomcat远程debug
- 109. Convert Sorted List to Binary Search Tree
- 线程的生死
- 我为什么选择了sublime text