LINK

题意:给出两个数n, s,要求问1~n中\(x-bit(x)>=s\)的数有多少个。其中bit(x)指x的各位数之和

思路:首先观察能够发现,对于一个数如果满足了条件,由于x-bit(x)总是随x变大而变大的,所以只要求得最小的x能够满足条件,二分即可

/** @Date    : 2017-07-02 11:17:55
* @FileName: 817C 二分.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL n, s; LL trans(LL x)
{
LL res = 0;
while(x)
{
res += x % 10;
x /= 10;
}
return res;
}
int main()
{
while(cin >> n >> s)
{
LL l = 1, r = 1e18 + 20;//注意范围
if(s >= n)//注意s可能大于n
{
printf("0\n");
continue;
}
while(l < r)
{
LL mid = (l + r) >> 1;
if(mid - trans(mid) >= s)
r = mid;
else l = mid + 1; //cout << l << '~' << r << endl;
//cout << mid << "~" << trans(mid) << endl;
}
if(l > n)
printf("0\n");
else
printf("%lld\n", n - l + 1);
}
return 0;
}

817C. Really Big Numbers 二分的更多相关文章

  1. Really Big Numbers CodeForces - 817C (数学规律+二分)

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. Codeforces 817C Really Big Numbers - 二分法 - 数论

    Ivan likes to learn different things about numbers, but he is especially interested in really big nu ...

  3. Codeforces 359D Pair of Numbers | 二分+ST表+gcd

    题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...

  4. Codeforces 817+818(A~C)

    (点击题目即可查看原题) 817A Treasure Hunt 题意:给出起点和终点,每次移动只能从 (a,b)移动至(a+x,b+y) , (a+x,b-y) , (a-x,b+y) , (a-x, ...

  5. AC自动机-算法详解

    What's Aho-Corasick automaton? 一种多模式串匹配算法,该算法在1975年产生于贝尔实验室,是著名的多模式匹配算法之一. 简单的说,KMP用来在一篇文章中匹配一个模式串:但 ...

  6. Binary Search

    Binary Search                              [原文见:http://www.topcoder.com/tc?module=Static&d1=tuto ...

  7. Python实例手册

    在电脑中突然发现一个这么好的资料,雪松大神制作,不敢独享,特与大家共享.连他的广告也一并复制了吧! python实例手册 #encoding:utf8 # 设定编码-支持中文 0说明 手册制作: 雪松 ...

  8. CF1036C Classy Numbers dfs+二分

    Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  9. UVa 10539 (筛素数、二分查找) Almost Prime Numbers

    题意: 求正整数L和U之间有多少个整数x满足形如x=pk 这种形式,其中p为素数,k>1 分析: 首先筛出1e6内的素数,枚举每个素数求出1e12内所有满足条件的数,然后排序. 对于L和U,二分 ...

随机推荐

  1. A9

    今日内容: 解决队友提出的问题 明日计划: 商讨界面还有哪些不足的地方 困难: 每天大部分时间被电工实习占走了

  2. NSURLErrorDomain错误代码

    kCFURLErrorUnknown = -998, kCFURLErrorCancelled = -999, kCFURLErrorBadURL = -1000, kCFURLErrorTimedO ...

  3. MySQL 备份和恢复 理论知识

    为什么要备份 数据无价   制定备份策略的注意点 1:可容忍丢失多少数据     2:恢复需要在多长时间内完成     3:备份的对象   数据.二进制日志和InnoDB的事务日志.SQL代码(存储过 ...

  4. 【BioCode】读文件夹以发现缺失文件

    代码说明: 使用单个蛋白质的txt计算PSSM生成的结果为单个的PSSM文件. 但是由于一些原因(如蛋白质序列过长),会导致一些蛋白质txt文件无法计算出pssm,为了找到这些没有计算出pssm的蛋白 ...

  5. PAT 甲级 1127 ZigZagging on a Tree

    https://pintia.cn/problem-sets/994805342720868352/problems/994805349394006016 Suppose that all the k ...

  6. websocket服务器+客户端

    <?php $demo = new ws('192.168.90.47',12345); $demo->run(); class ws { //当前服务端主连接 private $curr ...

  7. oracle 数据库 命令

    SQL PLUS 命令: SELECT * FROM ALL_TABLES;系统里有权限的表SELECT * FROM DBA_TABLES; 系统表SELECT * FROM USER_TABLES ...

  8. 卸载iptables 小心了!!怎么关闭和卸载iptables

    千万千万不要使用下面的命令卸载iptables yum remove iptables 这样操作会卸载掉很多系统必要的组件,那就开不了机了,链接不上了.切记切记. 如果想永远停用,使用以下命令即可: ...

  9. [codeforces743E]Vladik and cards

    E. Vladik and cards time limit per test  2 seconds memory limit per test  256 megabytes input standa ...

  10. Android APK 反编译步骤

    dex2jar和jd-gui工具下载,链接:http://yun.baidu.com/share/link?shareid=2888715259&uk=1377615098 解压APK文件得到 ...