CodeForces 219B Special Offer! Super Price 999 Bourles!
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int nn(long long a)
{
int si=;
while(a)
{
a=a/;
si++;
}
return si;
} long long po(long long s,int y)
{
for(int i=;i<=y;i++)
{
s=s*;
}
return s;
} int main()
{
long long p,d,Q;
int n,i,j,k;
while(scanf("%I64d %I64d",&p,&d)!=EOF)
{
n=nn(p);
if(n==)
printf("%I64d\n",p);
else
for(i=;i<=n;i++)
{
Q=po(p/po(,n-i),n-i);
for(j=n-i;j>=;j--)
{
Q=Q+po(,j-);
}
if(Q==p)
{
printf("%I64d\n",Q);
break;
}
Q=po(p/po(,n-i)-,n-i);
for(j=n-i;j>=;j--)
{
Q=Q+po(,j-);
}
if(p-Q<=d)
{
printf("%I64d\n",Q);
break;
}
}
}
return ;
}
CodeForces 219B Special Offer! Super Price 999 Bourles!的更多相关文章
- 构造 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 ...
- Special Offer! Super Price 999 Bourles!
Description Polycarpus is an amateur businessman. Recently he was surprised to find out that the mar ...
- codeforces Rockethon 2015 C Second price auction [想法]
传送门 C. Second price auction time limit per test 2 seconds memory limit per test 256 megabytes input ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- Codeforces 1383F - Special Edges(状态压缩+最大流)
Codeforces 题目传送门 & 洛谷题目传送门 首先暴力显然是不行的,如果你暴力最大流过了我请你吃糖 注意到本题的 \(k\) 很小,考虑以此为突破口解题.根据最大流等于最小割定理,点 ...
- codeforces 1156E Special Segments of Permutation
题目链接:https://codeforc.es/contest/1156/problem/E 题目大意: 在数组p中可以找到多少个不同的l,r满足. 思路: ST表+并查集. ST表还是需要的,因为 ...
- Codeforces 1156E Special Segments of Permutation(单调栈)
可以用单调栈直接维护出ai所能覆盖到的最大的左右范围是什么,然后我们可以用这个范围暴力的去查询这个区间的是否有满足的点对,一个小坑点,要对左右区间的大小进行判断,只需要去枚举距离i最近的一段区间去枚举 ...
- Codeforces 1156E Special Segments of Permutation(启发式合并)
题意: 给一个n的排列,求满足a[l]+a[r]=max(l,r)的(l,r)对数,max(l,r)指的是l到r之间的最大a[p] n<=2e5 思路: 先用单调栈处理出每个点能扩展的l[i], ...
- Codeforces Round #135 (Div. 2)
A. k-String 统计每个字母出现次数即可. B. Special Offer! Super Price 999 Bourles! 枚举末尾有几个9,注意不要爆掉\(long\ long\)的范 ...
随机推荐
- sklearn
Feature extraction - sklearn文本特征提取 http://blog.csdn.net/pipisorry/article/details/41957763 http://sc ...
- vim下正则表达式的非贪婪匹配
贪婪模式是: .* 非贪婪模式是: .\{-}
- 使用 nano 的时候提示找不到 libncursesw.so.5 这个共享库
由于拿nano来练习pacman这个包管理系统,也就是卸了装,装了卸.但是后来当我想用 nano 编辑文件的时候,系统提示标题上说的这错误. 不知道做了什么,难道是误删了什么东西...后来几番搜索,用 ...
- 给Debian浏览器安装flash播放插件
sudo apt-get install flashplugin-nonfree
- 「LAMP」在ubuntu及其衍生版上 安装LAMP
在Ubuntu上安装LAMP 此种方法在Linux Mint 13/14/15/16/17.Ubuntu 12.10(Quantal Quetzal)和Ubuntu 13.04 Raring Ring ...
- asp.net中获得客户端的IP地址
asp.net中获得客户端的IP地址 因为要在项目中取到客户端IP,在网上搜了下相关资料,其中有一篇文章总结的比较详细,这里就把一些我用的上总结一下 方便以后查阅. 通常我们都通过下面的代码获得IP ...
- HAVING用法详解
HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELECT 的交互方式类似.WHERE 搜索条件在进行分组操作之前应用:而 HAVING 搜索条件在进行分组操作之后应用 ...
- Date() 及其 如何验证用户输入的日期是合法的
1.var someDate = new Date(Date.parse("May 25, 2004")); <=> var someDate = new Dat ...
- 指针二次释放(_BLOCK_TYPE_IS_VALID)
[1]_BLOCK_TYPE_IS_VALID是什么错误? (1)最简单的示例代码如下: void main() { ); delete pA; delete pA; } (2)运行后崩溃截图如下: ...
- NEON在Android中的使用举例【转】
转自:http://blog.csdn.net/fengbingchun/article/details/37766607 版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 打开Eclip ...