codeforces817c Really Big Numbers

本文介绍了一种计算特定条件下特殊大数数量的方法。通过定义一个函数f(x),该函数表示x与其各位置上的数字之和的差值,并利用此函数的单调性特性,采用二分搜索算法高效求解不超过n的所有特殊大数的数量。
C. Really Big Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than n.

Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.

Input

The first (and the only) line contains two integers n and s (1 ≤ n, s ≤ 1018).

Output

Print one integer — the quantity of really big numbers that are not greater than n.

Examples
input
12 1
output
3
input
25 20
output
0
input
10 9
output
1
Note

In the first example numbers 1011 and 12 are really big.

In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 3030 - 3 ≥ 20).

In the third example 10 is the only really big number (10 - 1 ≥ 9).

令f(x)为x-(x各位数之和)

可以看出f(x)是单调不减的

设y>x

若x 与 y只有个位不同 则f(x)==f(y)

反之f(x)>f(y)

若x各位数之和小于y 则必然成立

若x各位数之和等于y 因为x>y 所以成立

若x各位数之和大于y 则x至少有一位大于y对应的那一位

设只有一位

设其为右数第i位 则从最后一位-第i-1位f(y)-f(x)>0 

又因为x各位数之和大于y所以到第i位f(x)-f(y)至少为(j+1)*10^(i-1)-j j为i位之后 y各位和-x各位和

显然成立

若有多位 则可把所有这样的位合并

同一位

所以可以二分答案(二分出合法的 再算出不合法的)

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
inline LL get(LL x){
	LL ans=0;
	while(x){
		ans+=x%10;
		x/=10;
	}
	return ans;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	LL n,s;
	scanf("%I64d %I64d",&n,&s);
	LL l=0,r=n;
	while(l+1<r){
		LL mid=(l+r)>>1;
		if(mid-get(mid)<s)
			l=mid;
		else r=mid-1;
	}
	if(r-get(r)<s)
		printf("%I64d\n",n-r);
	else printf("%I64d\n",n-l);
return 0;
}


内容概要:本文介绍了一个基于多传感器融合的定位系统设计方案,采用GPS、里程计和电子罗盘作为定位传感器,利用扩展卡尔曼滤波(EKF)算法对多源传感器数据进行融合处理,最终输出目标的滤波后位置信息,并提供了完整的Matlab代码实现。该方法有效提升了定位精度与稳定性,尤其适用于存在单一传感器误差或信号丢失的复杂环境,如自动驾驶、移动采用GPS、里程计和电子罗盘作为定位传感器,EKF作为多传感器的融合算法,最终输出目标的滤波位置(Matlab代码实现)机器人导航等领域。文中详细阐述了各传感器的数据建模方式、状态转移与观测方程构建,以及EKF算法的具体实现步骤,具有较强的工程实践价值。; 适合人群:具备一定Matlab编程基础,熟悉传感器原理和滤波算法的高校研究生、科研人员及从事自动驾驶、机器人导航等相关领域的工程技术人员。; 使用场景及目标:①学习和掌握多传感器融合的基本理论与实现方法;②应用于移动机器人、无人车、无人机等系统的高精度定位与导航开发;③作为EKF算法在实际工程中应用的教学案例或项目参考; 阅读建议:建议读者结合Matlab代码逐行理解算法实现过程,重点关注状态预测与观测更新模块的设计逻辑,可尝试引入真实传感器数据或仿真噪声环境以验证算法鲁棒性,并进一步拓展至UKF、PF等更高级滤波算法的研究与对比。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值