题目链接:

http://hihocoder.com/problemset/problem/1301?sid=804672

题解:

二分答案,每次判断用数位dp做。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; typedef long long LL;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL; //dp[x][0]表示高位还没有出现4,7。
//dp[x][1]表示高位已经出现4,7了。
LL dp[][];
bool vis[][];
LL k; int num[];
//z表示高位是不是刚好在最大的边界上。
LL dfs(int cur, int y, int z) {
if (cur == - && y) return ;
if (cur == -) return ;
if (vis[cur][y] && !z) return dp[cur][y];
int e = z ? num[cur] : ;
LL res = ;
for (int i = ; i <= e; i++) {
res += dfs(cur - , y || i == || i == , z && (i == e));
}
if (!z) {
dp[cur][y] = res;
vis[cur][y] = ;
}
return res;
} bool ok(LL x) {
int tot = ;
while (x) {
num[tot++] = x % ;
x /= ;
}
memset(dp, , sizeof(dp));
memset(vis, , sizeof(vis));
LL res = dfs(tot - , , );
return res<k;
} int main() {
while (scanf("%lld", &k) == ) {
LL l = , r = INFLL;
//printf("r:%lld\n", r);
while (l + < r) {
LL mid = l + (r - l) / ;
if (ok(mid)) l = mid;
else r = mid;
}
printf("%lld\n", l + );
}
return ;
}

hihocoder #1301 : 筑地市场 数位dp+二分的更多相关文章

  1. hihocoder #1301 : 筑地市场 二分+数位dp

    #1301 : 筑地市场 题目连接: http://hihocoder.com/problemset/problem/1301 Description 筑地市场是位于日本东京都中央区筑地的公营批发市场 ...

  2. hihoCoder #1301 : 筑地市场 (打表+构造)

    题目大意:问含有4或者7的第k大的正数是多少. 题目分析:1~10.1~100.1~1000...之间的含有4或者7的个数可以求出,这样就可以从高位到地位依次确定这个数的每一位上的值. 代码如下: # ...

  3. poj3208 Apocalypse Someday 数位dp+二分 求第K(K <= 5*107)个有连续3个6的数。

    /** 题目:poj3208 Apocalypse Someday 链接:http://poj.org/problem?id=3208 题意:求第K(K <= 5*107)个有连续3个6的数. ...

  4. hihoCoder #1770 : 单调数(数位dp)

    题面 我们定义一个数是单调数,当且仅当构成这个数每一个数位都是单调不降或不增的. 例如 \(123\) 和 \(321\) 和 \(221\) 和 \(111\) 是单调的,而 \(312\) 不是单 ...

  5. UPC 2223: A-Number and B-Number(数位DP+二分)

    积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要 ...

  6. CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)

    All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...

  7. hdu 3271 SNIBB 数位DP+二分

    思路:dp[i][j]:表示第i位在B进制下数字和. 用二分找第k个数! 代码如下: #include<iostream> #include<stdio.h> #include ...

  8. [uva 1350]数位dp+二分

    题目链接:https://vjudge.net/problem/38405 #include<bits/stdc++.h> using namespace std; ][]; ]; lon ...

  9. 【HIHOCODER 1033 】 交错和(数位DP)

    描述 输入 输入数据仅一行包含三个整数,l, r, k(0 ≤ l ≤ r ≤ 1018, |k| ≤ 100). 输出 输出一行一个整数表示结果,考虑到答案可能很大,输出结果模 109 + 7. 提 ...

随机推荐

  1. 在Windows Server 2012 中安装 .NET 3.5 Framework,PowerShell 安装.NET FRAMEWORK

    问题 如今,仍然有许多程序和应用需要依靠.NET 3.5 framework 来运行.在Windows Server 2012中,微软提供了.NET 3.5 和.NET 4.5的安装选项以为你的应用程 ...

  2. PHP 创建重用数据库连接函数 mysqli与PDO

    代码如下: 有兴趣的可以测试下 摘自于某书 <? php public function dbConnect( $usertype, $connectionType = 'mysqli' ) { ...

  3. 导航栏 UITabBarController等颜色的区别

    //tint color是设置你选中的那个tabBar的颜色,默认是蓝色,点击是设置的红色    vc.tabBar.tintColor = [UIColor redColor];        // ...

  4. Weex

    今天在群友发的那个掘金技术网站里头看到这个weex,感觉还不错 阿里负责的一个开源项目 源码地址: http://alibaba.github.io/weex/index.html 是用来做app的 ...

  5. Python 字典(Dictionary) setdefault()方法

    描述 Python 字典(Dictionary) setdefault() 函数和get()方法类似, 如果键不已经存在于字典中,将会添加键并将值设为默认值. 语法 setdefault()方法语法: ...

  6. webSphere集群部署主要步骤

    1.系统管理-节点,添加本机节点和另外一台机器的节点2.建立集群服务cluster,添加成员节点3.将应用部署到集群服务cluster4.将数据库源分别建立到节点作用域5.后续步骤参照安装手册 注意事 ...

  7. While readingiphone真机无法显示图片,而模拟器可以正常显示

    可能,很多开发IOS程序的遇到过在模拟器里,加载图片都是正常的,但是在真机里就会出现图片资源不能加载的问题. 其中一种原因是,在Simulator里面,例如:图片资源名称为:a.PNG,在代码你里,你 ...

  8. 【风马一族_Android】 图能

    ---------------------------------- 第一次 名称:相片查看器 ---------------------------------- 通过3D.自动播放幻灯片.旋转.跳 ...

  9. c++11: bind用法

    原型: template< class R, class F, class... Args > bind( F&& f, Args&&... args ); ...

  10. JQGrid+Webservice+LINQ

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jqgridtest.asp ...