B. Special Offer! Super Price 999 Bourles!
来源:互联网 发布:淘宝超过7天还能退货吗 编辑:程序博客网 时间:2024/05/21 22:24
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
解题说明:题意就是一个物品有一个价格,这个价格可以最多降低d,求在所下降价格不超过d的情况下,能够使价格有最多的9且价格最高。思路是从价格的最后一位开始往前遍历,每次查找最后n位与n个9组成的数之间的差值,如果这个差值在范围内就接受。
#include <iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;int main(){ long long p, d, i, m = 0; scanf("%lld%lld", &p, &d); if (p < 10){printf("%lld\n", p);}else { for (i = 10 ; i <= p ; i *= 10) { if (p % i + 1 == i) {continue; } if (p % i + 1 <= d) { m = p % i + 1; } else { break; } } printf("%lld\n", p - m); } return 0;}
- B. Special Offer! Super Price 999 Bourles!
- CF 135 DIV2 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
- codeforce_219B Special Offer! Super Price 999 Bourles!
- Special Offer! Super Price 999 Bourles!
- Codeforces Round #135 (Div. 2) B. 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!(贪心)
- Magento 把所有产品的Special Price的值,给Group Price,然后清空Special Price的值
- magento special price 加入购物车之后变为原价
- Magento 把所有产品的 Special Price 同步添加给Group Price代码
- Mangeto批量修改价格:把price的值赋值给special price
- B - Super long sums
- Problem B. Super 2048
- Price
- probe在什么时候调用
- 正则表达式-入门
- [UNIX域Socket抽象命名空间(abstract_namespace)]
- 妈咪,我找到了!15实用的Linux find命令示例
- Oracle 存储过程 使用示例 .
- B. Special Offer! Super Price 999 Bourles!
- 输出含7、8和能被7、8整除的数,以及用C++stl做数组的全排列
- 用excel vba,将EXCEL数据追加到ACCESS数据库的某张表中的实例(学习备注)
- ios [UIImage class]: message sent to deallocated instance
- ios开发关于用户跳转app store评价app
- 如何删除叙事簿上的列设置格式。
- IT English Collection(11)of Object graph
- <one-to-one name="iUser" constrained="true"></one-to-one> 的含义
- 利用jmeter和jconsole进行压力测试