zoukankan      html  css  js  c++  java
  • 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 ≤ 10180 ≤ 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

    Input
    1029 102
    Output
    999
    Input
    27191 17
    Output
    27189

    题目意思:人们通常对最后带有99的价格比较动心,于是这一个业余商人发现这个商机,决定打折,使价格接近带有99的数,但是又不能为了得到带有最多9的数而减价太多,
    所以有一个限度d,减价幅度不能超过d
    解题思路:我们可以换一个想法使最后得到的价格的结尾0最多,然后只要减去一个1就能得到最多的9

     1 #include<stdio.h>
     2 int main()
     3 {
     4     long long int p,d,ans,t;
     5     while(scanf("%lld%lld",&p,&d)!=EOF)
     6     {
     7         t=10;
     8         p=p+1;
     9         ans=p;
    10         while(1)
    11         {
    12             if(p%t>d)
    13             {
    14                 break;
    15             }
    16             ans=p-p%t;
    17             t=t*10;
    18         }
    19         printf("%lld
    ",ans-1);
    20     }
    21    return 0;
    22 }


  • 相关阅读:
    解决GOOGLE不能用的办法
    Elmah错误日志工具
    Linq 更改主键值
    qcow2、raw、vmdk等镜像格式
    Ceph相关博客、网站(256篇OpenStack博客)
    Delphi中inherited问题
    Qt qss一些伪装态,以及margin与padding区别
    Qt双缓冲机制:实现一个简单的绘图工具(纯代码实现)
    写出一篇好博文需要用到的工具
    最短路径启蒙题
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9208986.html
Copyright © 2011-2022 走看看