转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=279&page=show_problem&problem=3930

 

题意:问第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)的更多相关文章

  1. Space Elevator [POJ2392] [DP][优化]

    题目大意 n件物品,第i件hi高,有ci件,最高的一件不能超过ai的高度.问最高能堆多高 输入: 第一行,一个n 接下来每一行,为hi,ai,ci 输出,最高堆多高 样例输入: 37 40 35 23 ...

  2. POJ 2392 Space Elevator 贪心+dp

    题目链接: http://poj.org/problem?id=2392 题意: 给你k类方块,每类方块ci个,每类方块的高度为hi,现在要报所有的方块叠在一起,每类方块的任何一个部分都不能出现在ai ...

  3. HDU 3709 Balanced Number (数位DP)

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  4. HDU3709 Balanced Number (数位dp)

     Balanced Number Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Descript ...

  5. 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)

    BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...

  6. 【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 ...

  7. 【HDU 3709】 Balanced Number (数位DP)

    Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...

  8. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  9. A - Space Elevator(动态规划专项)

    A - Space Elevator Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. SQL复制表结构和数据

    1.复制表结构和数据 select * into 目的数据库名.dbo.目的表名 from 原表名 select * into my0735home.dbo.infoMianTest from inf ...

  2. C# 文件读写异常“正由另一进程使用,因此该进程无法访问该文件”

    最近在对文件进行读写操作时,利用using的方法可还是遇到了异常"文件正由另一进程使用,因此该进程无法访问该文件": public bool WriteUserInfo(strin ...

  3. DotNET知识点总结四(笔记整合)

    1.枚举:本质是类 如果为第一个枚举赋了一个int值,那么后面的枚举项依次递增 可以将枚举强转成他所代表的int值 C#的枚举项都是常量(可以用Reflector查看literal的IL源码) 因为枚 ...

  4. 配置android开发环境eclipse获取ADT获取不到

    在安装完Android SDK后eclipse要获取ADT, 可是由于GFW的存在, eclipse经常无法从http://dl-ssl.google.com/android/eclipse 获取到任 ...

  5. iOS 定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等授权检测

    金田 iOS系统版本的不断升级的前提,伴随着用户使用设备的安全性提升,iOS系统对于App需要使用的硬件限制也越来越严格,App处理稍有不妥,轻则造成功能不可用用户还不知道,重则会造成App Cras ...

  6. hdu-1800

    思路: 这题被坑的不轻. 首先花了一段时间想明白了思路是要找出现次数最多数字,以为这题就这样解决了,结果发现每个数字的最大长度是30,long long都装不下,因此就要用字符串来保存处理.然后在in ...

  7. MD中bitmap源代码分析--数据结构

    本篇分析bitmap的数据结构的设计,并基于此分析bitmap的工作机制. 为了后面更清楚的理解,先有个总体印象,给出整体的结构图: 在下面的描述中涉及到的内容可以对照到上图中相应部分,便于理解. 首 ...

  8. linux0.12 链接过程

    终于编译OK了..可链接就是一大堆错误 问题1: boot/head.o: In function `startup_32': (.text+0x10): undefined reference to ...

  9. vmware vms migration to openstack

    Converting a VMware Workstation virtual machine to KVM Leave a commentPosted by rbgeek on August 13, ...

  10. Java组合与继承生成的类中构造函数的执行顺序

    [程序实例] import java.util.*; class Meal{ Meal() { System.out.println("Meal Constructor"); } ...