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\)的范 ...
随机推荐
- IIS 浏览aspx页面出现 无法显示 XML 页
问题: 无法显示 XML 页. 使用 XSL 样式表无法查看 XML 输入.请更正错误然后单击 刷新按钮,或以后重试. 名称以无效字符开头.处理资源 'http://192.168.1.254:808 ...
- XMl的解析简单的方法
首先需要jia包 xstream-1.4.7.jar Vo类 package com.zld.day06_03zk3demo.bean; import java.io.Serializable; im ...
- Qunar实习回顾总结
今天教师节,陪老师喝点小酒,回来难得抽空,整理一下实习阶段的那些零零碎碎却很有用的知识. 1.关于页面中嵌入js代码 (1)有时为了精确控制代码执行顺序流,会将js代码嵌入到网页之中.优点:改变代码触 ...
- ==,equal,hasCode(),identifyHasCode()浅析
在java中如果我们要比较两个对象之间的关系的话有可能会用到下面的几种方法:==,equal,hasCode(),identifyHasCode(). ==用来比较对象本身是不是相同的. public ...
- 统一使用GPT分区表,安装MAC 10.10 和 Win8.1 pro双系统
步骤一: 为Mac OS 分区,为其它分区留白1,使用OSX Mavericks制作的Mac安装U盘按住Option键启动:2,选择安装Mavericks盘符:3,进入OSX安装启动界面,选择磁盘工具 ...
- SoupUI的使用
- python实现文章或博客的自动摘要(附java版开源项目)
python实现文章或博客的自动摘要(附java版开源项目) 写博客的时候,都习惯给文章加入一个简介.现在可以自动完成了!TF-IDF与余弦相似性的应用(三):自动摘要 - 阮一峰的网络日志http: ...
- 高并发 php uniqid 用md5生成不重复唯一标识符方案
高并发 php uniqid 用md5生成不重复唯一标识符方案uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.uniqid(prefix,more_entropy)prefix 可 ...
- Angular.js为什么如此火呢?
在本文中让我们来逐步发掘angular为什么如此火: Angular.js 是一个MV*(Model-View-Whatever,不管是MVC或者MVVM,统归MDV(model Drive View ...
- Linux内核调试方法总结【转】
转自:http://my.oschina.net/fgq611/blog/113249 内核开发比用户空间开发更难的一个因素就是内核调试艰难.内核错误往往会导致系统宕机,很难保留出错时的现场.调试内核 ...