Special Offer! Super Price 999 Bourles!
Description
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price.
Input
The first line contains two integers p and d (1 ≤ p ≤ 1018; 0 ≤ d < p) — the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
Print the required price — the maximum price that ends with the largest number of nines and that is less than p by no more than d.
The required number shouldn't have leading zeroes.
Sample Input
1029 102
999
27191 17
27189 题目意思:人们通常对最后带有99的价格比较动心,于是这一个业余商人发现这个商机,决定打折,使价格接近带有99的数,但是又不能为了得到带有最多9的数而减价太多,
所以有一个限度d,减价幅度不能超过d
解题思路:我们可以换一个想法使最后得到的价格的结尾0最多,然后只要减去一个1就能得到最多的9
#include<stdio.h>
int main()
{
long long int p,d,ans,t;
while(scanf("%lld%lld",&p,&d)!=EOF)
{
t=;
p=p+;
ans=p;
while()
{
if(p%t>d)
{
break;
}
ans=p-p%t;
t=t*;
}
printf("%lld\n",ans-);
}
return ;
}
Special Offer! Super Price 999 Bourles!的更多相关文章
- CodeForces 219B Special Offer! Super Price 999 Bourles!
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO For ...
- 构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio&g ...
- Codeforces Round #135 (Div. 2)
A. k-String 统计每个字母出现次数即可. B. Special Offer! Super Price 999 Bourles! 枚举末尾有几个9,注意不要爆掉\(long\ long\)的范 ...
- 我一个二本大学是如何校招拿到阿里offer的
作者:薛勤,互联网从业者,编程爱好者. 本文首发自公众号:代码艺术(ID:onblog)未经许可,不可转载 01:终于步入大学 我既没有跨过山和大海,也没有穿过人山人海,我就是我,一个普通本科大学生. ...
- 我一个二本大学是如何拿到阿里offer的
作者:薛勤,互联网从业者,编程爱好者. 本文首发自公众号:代码艺术(ID:onblog)未经许可,不可转载 01:终于步入大学 我既没有跨过山和大海,也没有穿过人山人海,我就是我,一个普通本科大学生. ...
- [转]9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...
- 9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...
- offer档次排名,2014最新版
转自:http://tieba.baidu.com/p/2748469183 综合考虑发展,薪水,环境,压力. 第0档:美国互联网总部special offer(15万刀起薪) 第一档: 股份制银行总 ...
- (转)9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
原文:http://www.cnblogs.com/figure9/archive/2013/01/09/2853649.html 1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也 ...
随机推荐
- UDP实现网络通信程序
VC6.0创建基于UDP协议的网络聊天程序 只有一个工程UDP,服务器和客户端都是这个工程,因为UDP中C/S区分不强化 只讲关键部分,避免累赘 1.为对话框添加控件 2.为控件绑定变量和消息函数 启 ...
- Redis的数据类型以及各类型的操作
讲完安装和配置,接下来就是所有数据库的重头戏,数据结构和常用操作的增删改查了 redis是key-value的数据结构,每条数据都是⼀个键值对 键的类型是字符串 注意:键不能重复 值的类型分为五种: ...
- pastedeploy
3.1作用 不修改WSGI应用程序的情况下通过配置文件配置WSGI服务. filter:过滤器,滤网. pipline:管道 app:application 应用,在这个语境下我举个例子吧,lavab ...
- 转:Java中的cas
引自:https://blog.csdn.net/mmoren/article/details/79185862 本篇的思路是先阐明无锁执行者CAS的核心算法原理然后分析Java执行CAS的实践者Un ...
- Xcode9.2 添加iOS11.2以下旧版本模拟器
问题起源 由于手边项目需要适配到iOS7, 但是手边的测试机都被更新到最新版本,所以有些潜在的bug,更不发现不了.最近就是有个用户提出一个bug,而且是致命的,app直接闪退.app闪退,最常见的无 ...
- 如何快速生成数据库字典(thinkphp5.0)
本教程将教你快速生成数据库字典 示例代码使用PHP框架:Thinkphp5.0 PHP代码: /** * 生成数据库字典html * 可直接另存为再copy到word文档中使用 * * @return ...
- python的基本知识
1. python的简介 python的创始⼈人为吉多·范罗苏姆(Guido van Rossum).1989年年的圣诞节期间,吉多· 范罗苏姆为了了在阿姆斯特丹丹打发时间,决⼼心开发⼀个新的脚 ...
- zkfc的znode不存在的问题
cd /soft/hadoop/logs/hadoop-centos-zkfc-s101.log发现: 2018-09-29 12:42:03,616 FATAL org.apache.hadoop. ...
- Python学习手册之数据封装、类方法、静态方法和属性函数
在上一篇文章中,我们介绍了 Python 的内部方法.操作符重载和对象生命周期,现在我们介绍 Python 的数据封装.类方法.静态方法和属性函数.查看上一篇文章请点击:https://www.cnb ...
- 从零开始一个http服务器(三)-返回response 构造
从零开始一个http服务器(三) 代码地址 : https://github.com/flamedancer/cserver git checkout step3 运行: gcc request.h ...