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 ...
随机推荐
- 设置CentOS里的Mysql开启客户端远程连接
CentOS系统安装好MySQL后,默认情况下不支持用户通过非本机连接上数据库服务器,下面是解决方法: 1.在控制台执行 mysql -u root -p mysql,系统提示输入数据库root用户的 ...
- 魔法方法:算术运算 - 零基础入门学习Python042
魔法方法:算术运算 让编程改变世界 Change the world by program 我现在重新提一个名词:工厂函数,不知道大家还有没有印象?我们在老早前就提到过Ta,由于那时候我们还没有学习类 ...
- Reaver v1.4 用法整理 含高级参数说明 pin必备资料
闲话少叙 使用方法: airmon-ng start wlan0 //启动mon0监控 reaver -i mon0 -b MAC -a -S -vv //普通用法 如果,90.9%进程后死机或停机, ...
- 转:窗口启用/禁用功能函数EnableWindow的使用
在非MFC环境中如何使控件或者窗口禁用呢?起初是想通过发送消息来实现,但找来找去都木有找到控件禁用的消息(也是是博主木有找到的缘故),所以只能另辟蹊径,使用 EnableWindow这个函数, 该函数 ...
- android http协议post请求方式
方式一:HttpPost(import org.apache.http.client.methods.HttpPost 代码如下: private Button button1,button2,but ...
- 64位linux中使用inet_ntoa报错处理
最近一直使用linux mint 15,我用的是64位操作系统,在进行网络编程的时候,发现一个问题,请看源码: /*get_ip_by_name.c*/ #include <stdio.h> ...
- java多线程入门
一.认识多任务.多进程.单线程.多线程 要认识多线程就要从操作系统的原理说起. 以前古老的DOS操作系统(V 6.22)是单任务的,还没有线程的概念,系统在每次只能做一件事情.比如你在copy东西 ...
- 【HDOJ】1513 Palindrome
DP,MLE后改为滚动数组AC. #include <cstdio> #include <cstring> #include <cstdlib> #define M ...
- HDOJ 1266 Reverse Number(数字反向输出题)
Problem Description Welcome to 2006'4 computer college programming contest! Specially, I give my bes ...
- navicat 随笔提示的快捷键
1.ctrl+q 打开查询窗口2.ctrl+/ 注释sql语句3.ctrl+shift +/ 解除注释4.ctrl+r 运行查询窗口的sql语句5.ctrl+shift+r 只运行选中的sql语句6. ...