Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
来源:互联网 发布:淘宝网浏览器官方下载 编辑:程序博客网 时间:2024/05/02 00:03
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.
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.
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.
1029 102
999
27191 17
27189
题意:输入p和d两个数,p减去小于等于d的一个数,使得尾数中9最多。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int main(){ long long p,q,i,j,k,s; while(~scanf("%lld%lld",&p,&q)) { p=p+1; long long s=p;//p+1是为了防止出现99999...这种情况和p==1 for(i=10;;i*=10) { if(p%i>q) break; s=p-p%i; } printf("%lld\n",s-1); } return 0;}
- Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
- codeforces B. Special Offer! Super Price 999 Bourles!
- codeforces 219B Special Offer! Super Price 999 Bourles!
- 【CodeForces 219B】Special Offer! Super Price 999 Bourles
- B. Special Offer! Super Price 999 Bourles!
- CF 135 DIV2 B Special Offer! Super Price 999 Bourles!
- codeforce_219B Special Offer! Super Price 999 Bourles!
- Special Offer! Super Price 999 Bourles!
- CF 135 DIV2 B Special Offer! Super Price 999 Bourles! 思维
- cf 想法 Special Offer! Super Price 999 Bourles!
- CF219B:Special Offer! Super Price 999 Bourles!(贪心)
- Codeforces Round #249 (Div. 2) D. Special Grid
- Codeforces Round #277.5 (Div. 2) F. Special Matrices
- Codeforces Round #342 (Div. 2)--C. K-special Tables
- Codeforces Round #277.5 (Div. 2)-F. Special Matrices
- Codeforces Round #135 (Div. 2)——B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- 机器学习:推荐系统(Andrew Ng Coursera课程)
- java中将数据导入excel,解决乱码,缺少jar包问题
- 第三周作业: 随机生成一个n bit位的长整数
- 改变计算技术的伟大算法(带动画演示)
- 用gdb调试程序的子进程
- Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
- 未整理电子书
- 18.报时助手
- VPS和VPN的区别
- 未整理电子书
- 持续更新的要弄懂的题
- Android的2D画图(一)
- 19.2n皇后问题
- 1050 [HAOI2006] 旅行comf 题解