题目意思大概是给你w,m,k三个数,让你从m开始找 m m+1 m+2 m+3...........m+m', 使得他们的权值之和不超过w,计算权值的方法如下S(n)·k
。 S(n)表示n有多少位数,让你计算出最多有多少个这样的数。

乍一眼看去,10^16如此大的数肯定不能暴力,然后稍微思考一下就可以找到规律了,规律如下。

1-10              有9个一位数

1-100            有9个一位数 有90个二位数

1-1000          有9个一位数 有90个二位数  有900个三位数

1-10000        有9个一位数 有90个二位数  有900个三位数  有9000个四位数

。。。。。。。。。。。。

那么1-n有多少个几位数很快就可以计算出来了,然后用二分法计算结果。代码如下

#include <stdio.h>
#include <iostream>
#define ll long long
#define inf 100000000000000000
//二分上界必须大于10^16,不然会出错 using namespace std; ll w, m, k; ll getans(ll x)
{
ll cmp = 10;
ll add = 9;
ll ans = 0;
ll sum = 0;
ll cnt = 1;
while (x >= cmp)
{
sum += add;
ans += add*cnt;
cnt++;
add *= 10;
cmp *= 10;
}
ans += (x - sum)*cnt;
return ans;
} inline ll getval(ll x)
{
return (getans(x)-getans(m-1));
} ll binarysearch(ll l, ll r, ll val)
{
if (l == r)
{
while (getval(l) > val)
l--;
return l;
}
ll mid = (l + r) >> 1;
if (getval(mid) < val)
return binarysearch(mid+1, r, val);
else
return binarysearch(l, mid, val);
} int main()
{
while (cin >> w >> m >> k)
{
ll t = binarysearch(m, inf, w/k);// 二分的第三个参数必须这样,不能在其他地方乘,不然也会溢出
if (t < m)
puts("0");
else
cout << t - m + 1 << endl;
}
return 0;
}

Codeforces Round #219(Div. 2)373 B. Making Sequences is Fun(二分+找规律)的更多相关文章

  1. Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

    D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...

  3. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  4. Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想

    题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...

  5. Codeforces Round #219 (Div. 2) E. Watching Fireworks is Fun

    http://codeforces.com/contest/373/problem/E E. Watching Fireworks is Fun time limit per test 4 secon ...

  6. Codeforces Round #219 (Div. 1)(完全)

    戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...

  7. Codeforces Round #219 (Div. 1) C. Watching Fireworks is Fun

    C. Watching Fireworks is Fun time limit per test 4 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    B. Making Sequences is Fun time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 阿里云ECS发送企业邮件

    <?phpuse PHPMailer\PHPMailer\PHPMailer;require '../vendor/autoload.php'; $mail = new PHPMailer(tr ...

  2. webpack-simple之vagrant热加载

    "dev": "cross-env NODE_ENV=development webpack-dev-server --host 192.168.2.10 --port ...

  3. kubernetes实战篇之helm示例yaml文件文件详细介绍

    系列目录 前面完整示例里,我们主要讲解helm打包,部署,升级,回退等功能,关于这里面的文件只是简单介绍,这一节我们详细介绍一下这里面的文件,以方便我们参照创建自己的helm chart. Helm ...

  4. RABC权限控制(二级菜单实现)

    目前大部分系统由于用户体验,基本上菜单不会做的很深,以二级菜单为例,做了一个简单的权限控制实现,可精确到按钮级别(基于django),下面具体看看实现 1.表结构的设计 无论开发什么都需要先梳理清楚需 ...

  5. JDK源码分析系列02---ArrayList和LinkList

    ArrayList和LinkList的源码分析 概要 ArrayList和LinkList是常用的存储结构,不看源码先分析字面意思,Array意思是数组,可知其底层是用数组实现的,Link意思是链接, ...

  6. HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Problem Des ...

  7. LightGBM,面试会问到的都在这了(附代码)!

    1. LightGBM是什么东东 不久前微软DMTK(分布式机器学习工具包)团队在GitHub上开源了性能超越其他boosting工具的LightGBM,在三天之内GitHub上被star了1000次 ...

  8. js查询checkbox已选择的值

    $("input[id^=ck]").each(function(index,e){ if($(e).is(":checked")) { userArray.p ...

  9. 获取当前时间的MySql时间函数

    mysql> select current_timestamp(); +---------------------+ | current_timestamp() | +------------- ...

  10. InstallShield 2018 打包安装

    关于InstallShield 2018打包安装程序的使用 1. 下载InstallShield2018 建议使用新的版本,毕竟新的版本功能功能全.问题少.用户体验佳. 下载地址:http://www ...