uva12486 Space Elevator(数位dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
题意:问第n个各个数位上不出现连续的13和4的数是多少?从1开始算,n<=10^18
莫名奇妙地写跪了,重写一发就过了、、、
可以比较容易的得出小于等于x的满足那些要求的数有多少个,然后根据这个二分。直接二分答案。
注意需要用unsigned long long
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std;
#define rep(X, N) for(int X=0;X<N;X++)
#define dep(X, R, L) for(int X=R;X>=L;X--)
typedef unsigned long long ull; typedef unsigned long long ull;
ull dp[][];
int d[]; class TaskE {
public:
void solve(std::istream &in, std::ostream &out) {
//bign n; rep(i, )
rep(j, )dp[i][j] = ;
run();
ull n;
while (in >> n) {
ull ans = ;
ull l = ;
ull r = -;
while (l <= r) {
int f = ;
if ((l & ) && (r & ))f++;
ull mid = (r >> ) + (l >> ) + f;
if (gao(mid) <= n) {
ans = mid;
l = mid + ;
} else {
r = mid - ;
}
}
out << ans << endl;
}
} ull gao(ull n) {
ull ans = ;
int len = ;
while (n) {
d[++len] = n % ;
n /= ;
}
d[len + ] = ;
dep(i, len, ) {
rep(j, d[i]) {
if (d[i + ] != || j != ) {
ans += dp[i][j];
}
}
if (d[i] == || (d[i + ] == && d[i] == ))break;
}
return ans;
} void run() {
dp[][] = ;
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
for (int k = ; k <= ; k++) {
if (j != && !(j == && k == )) {
dp[i][j] += dp[i - ][k];
}
}
}
}
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
TaskE solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return ;
}
uva12486 Space Elevator(数位dp)的更多相关文章
- Space Elevator [POJ2392] [DP][优化]
题目大意 n件物品,第i件hi高,有ci件,最高的一件不能超过ai的高度.问最高能堆多高 输入: 第一行,一个n 接下来每一行,为hi,ai,ci 输出,最高堆多高 样例输入: 37 40 35 23 ...
- POJ 2392 Space Elevator 贪心+dp
题目链接: http://poj.org/problem?id=2392 题意: 给你k类方块,每类方块ci个,每类方块的高度为hi,现在要报所有的方块叠在一起,每类方块的任何一个部分都不能出现在ai ...
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- HDU3709 Balanced Number (数位dp)
Balanced Number Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)
BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...
- 【SPOJ 1182】 SORTBIT - Sorted bit squence (数位DP)
SORTBIT - Sorted bit squence no tags Let's consider the 32 bit representation of all integers i from ...
- 【HDU 3709】 Balanced Number (数位DP)
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...
- poj 2392 Space Elevator(多重背包+先排序)
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- A - Space Elevator(动态规划专项)
A - Space Elevator Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- PHP判断文章里是否有图片
用preg_match来检查内容里是否有匹配的“<img”,其实我们还用preg_match来判断很多东西,比如邮箱地址里是否有“@”等,下面用一小段代码来演示具体用法. $content=&q ...
- 大整数算法[09] Comba乘法(原理)
★ 引子 原本打算一篇文章讲完,后来发现篇幅会很大,所以拆成两部分,先讲原理,再讲实现.实现的话相对复杂,要用到内联汇编,要考虑不同平台等等. 在大整数计算中,乘法是非常重要的,因为 ...
- js 解析 json
1.简单的json格式 { "user": [ { "name":"name1", "age":24, "se ...
- 一条带分页的sql
SELECT * FROM (SELECT USERID, TYPE, TYPE_DESC, SEX, USERNAME, HEADPORTRAIT, HOSPITAL, HLEVEL, DEPT, ...
- 读、写SD上的文件请按如下步骤进行
1.调用Environment的getExternalStorageState()方法判断手机上是否插入了SD卡,并且应用程序具有读写SD卡的权限.例如使用如下代码//Environment.getE ...
- 如何修改Oracle用户密码
大家如果不知道oracle数据库的密码的话,我们可以通过简单的命令行把密码进行修改. 1.打开cmd 2 在弹出的命令提示窗口输入 set oracle_sid=数据库名称(实例),回车.例如数据库名 ...
- Geeks Interview Question: Ugly Numbers
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...
- Github开源Java项目(Disconf)上传到Maven Central Repository方法详细介绍
最近我做了一个开源项目 Disconf:Distributed Configuration Management Platform(分布式配置管理平台) ,简单来说,就是为所有业务平台系统管理配置文件 ...
- 【winform程序】自定义webrowser控件调用IE的版本
修改注册表: bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROW ...
- 【剑指Offer学习】【面试题56:链表中环的入口结点】
题目:一个链表中包括环.怎样找出环的入口结点? 解题思路 能够用两个指针来解决问题.先定义两个指针P1和P2指向链表的头结点.假设链表中环有n个结点,指针P1在链表上向前移动n步,然后两个指针以同样的 ...