转载请注明出处: 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. wordpress主题制作结构文件

    下面是WordPress主题文件层次结构,它会告诉你:当WordPress显示特定的页面类型时,会使用哪个模板文件呢?只有了解了以下主题层次结构,你才能知道你的WordPress主题到底需要写哪些文件 ...

  2. str_repeat() 函数

    <?php echo str_repeat(".",13);//重复几次 ?>

  3. php global范例

    Example #1 $GLOBALS 范例 <?phpfunction test() {    $foo = "local variable"; echo '$foo in ...

  4. Jasper_filter data_pass field data from main to sub to filter some data

    main report: 1 add variable <variable name="Variable_rule" class="java.lang.String ...

  5. NMAP扫描UDP123NTP端口详解

    我用的nmap版本:Zenmap 6.25 例如命令: nmap -sU -pU:123 -Pn -n --script=ntp-monlist IP 如果要批量进行,可以把IP存放在ip.txt可以 ...

  6. 转:exit()与_exit()的区别

    版权声明:本文为博主原创文章,未经博主允许不得转载. 从图中可以看出,_exit 函数的作用是:直接使进程停止运行,清除其使用的内存空间,并清除其在内核的各种数据结构:exit 函数则在这些基础上做了 ...

  7. 转:DSP学习经验

    转载:http://www.cnblogs.com/MrYang/archive/2010/12/21/1913035.html

  8. Xamarin Add Mac

    右键IOS项目,设置为启动项目,点击启动(F5)弹出如下提示 提示开启远程访问权限,按照提示照做即可 在mac端 进入系统偏好设置 双击选择共享 打开远程登陆,允许所有用户访问 设置完成后点击ok 弹 ...

  9. Oracle extent

    extent 上的块 物理上绝对连续 多个连续的block组成一个extent 不连续怎么多块读? Oracle 给表分配的单位是extent 去做 全表扫描的时候 以块为单位,按照extent来读取 ...

  10. 读UNDO引发的db file sequential read

    SQL> select * from (select SESSION_ID, NAME, P1, P2, P3, WAIT_TIME, CURRENT_OBJ#, CURRENT_FILE#, ...