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,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也 ...
随机推荐
- MySQL必知必会 读书笔记一:简介
了解数据库 数据库(database) 数据库(database) 保存有组织的数据的容器(通常是一个文 件或一组文件). 数据库软件应称为DBMS(数据库管理系统).数据库是通过DBMS创建和操纵的 ...
- redis的docker化安装
只需要关注几点: 端口映射 配置文件映射 持久化映射 要做的就是拉取官方镜像并把关注的几个点处理一下就好了: docker pull redis docker run -d -p : -v /data ...
- Macbook下安装memcached
参考文献: https://blog.csdn.net/weixin_41827162/article/details/82049520 感谢大佬 安装memcached需要Homebrew 注意点: ...
- php连接数据库(一)
1.php链接数据库: 1.链接数据库 2.判断是否连接成功 3.设置字符集 4.选择数据库 5.准备SQL语句 6.发送SQL语句 7.处理结果集 8.释放资源(关闭数据库) $result = m ...
- day30 进程
推荐两本书:现代操作系统和操作系统原来,学习好python以后再去研究. 并发:任务的切换,保存状态,存在io的是实现空间和时间的 重复利用 操作系统的发展历史: 第一代(1940-1955)手工 ...
- Java实例 Part1:Java基础输出语句
** Part1:Java基础输出语句 ** 第一部分最基础,就是标准的输出语句. ps:(目前还没熟悉这个编辑器,先尝试一下) Example01 : 输出"hello world&quo ...
- 基于TCP/IP的局域网聊天室---C语言
具备注册账号,群聊,查看在线人员信息,私发文件和接收文件功能,因为每个客户端只有一个属于自己的socket,所以无论客户端是发聊天消息还是文件都是通过这一个socket发送, 这也意味着服务器收发任何 ...
- Python递归二分法
# lst = [4, 56, 178, 253, 625, 1475, 2580, 3574, 15963] # 时间复杂度. n# # 让用户输入一个数n. 判断这个n是否出现在lst中# n = ...
- P2257 YY的GCD
P2257 YY的GCD 题目描述 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 k ...
- 推荐 的FPGA设计经验(4) 时钟和寄存器控制架构特性使用
Use Clock and Register-Control Architectural Features FPGAs provide device-wide clocks and register ...