转载请注明出处: 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. Apache Rewrite 拟静态配置54

    mod_rewrite 规则的使用 RewriteEngine on RewriteCond %{HTTP_HOST} !^www.php100.com  [NC]  RewriteRule   ^/ ...

  2. 导出函数结构 EXPORT_DIRECTORY

    typedef struct _IMAGE_EXPORT_DIRECTORY { DWORD Characteristics; DWORD TimeDateStamp; //输出表的创建时间 WORD ...

  3. Swift—Cocoa Touch设计模式-备

    目标(Target)与动作(Action)是iOS和OS X应用开发的中事件处理机制.   问题提出 如图所示是一个ButtonLabelSample案例设计原型图,其中包含一个标签和一个按钮,当点击 ...

  4. Chrome下的语音控制框架MyVoix.js使用篇(四)

    在上一篇博文中,我为大家介绍了myvoix.js中的smart learning模块,以及何如使用该功能.(myvoix.js的源码地址会在每一篇文章末尾放出) 文本将拓展 Chrome下的语音控制框 ...

  5. asp.net webapi参数绑定

    content={"content": [{"comb_id": "100323","comb_name": " ...

  6. Altium 9中正确的差分对走线方法

    1.在原理图中定义差分对在菜单中Place>>Directive为差分网络放置差分对指令.差分对网络名称必须以“_N”和“_P”作为后辍.对差分网络放置指令后要对其参数进行配置,包括Dif ...

  7. _CrtDumpMemoryLeaks报告程序中的内存泄露问题(简单示例代码)

    // .h 文件 #pragma once class CConsoleDump { public: explicit CConsoleDump(LPCTSTR lpszWindowTitle = N ...

  8. eclipse中格式化代码快捷键Ctrl+Shift+F失效的解决办法

    很长一段时间我的eclipse都有个毛病,就是当我要格式化代码的时候,右键-source-format能够起效,但ctrl+shift+f不好使了. 可以基本断定是快捷键与别的软件冲突了,但一直也没时 ...

  9. rsyslog 日志服务器接收日志权限问题

    rsyslog 权限: 默认 [root@dr-mysql01 zjzc_log]# ls -ltr zj-frontend0*-access*27 -rw------- 1 root root 32 ...

  10. 【转】Android 带checkbox的listView 实现多选,全选,反选----解决checkbox错位问题

    原文网址:http://blog.csdn.net/onlyonecoder/article/details/8687811 Demo地址(0分资源):http://download.csdn.net ...