zoukankan      html  css  js  c++  java
  • CodeForces 219B Special Offer! Super Price 999 Bourles!

    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 ≤ 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
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 int nn(long long a)
     7 {
     8     int si=0;
     9     while(a)
    10     {
    11         a=a/10;
    12         si++;
    13     }
    14     return si;
    15 }
    16 
    17 long long po(long long s,int  y)
    18 {
    19     for(int i=1;i<=y;i++)
    20     {
    21         s=s*10;
    22     }
    23     return s;
    24 }
    25 
    26 int main()
    27 {
    28     long long p,d,Q;
    29     int n,i,j,k;
    30     while(scanf("%I64d %I64d",&p,&d)!=EOF)
    31     {
    32         n=nn(p);
    33         if(n==1)
    34             printf("%I64d
    ",p);
    35         else
    36         for(i=1;i<=n;i++)
    37         {
    38             Q=po(p/po(1,n-i),n-i);
    39             for(j=n-i;j>=1;j--)
    40             {
    41                 Q=Q+po(9,j-1);
    42             }
    43             if(Q==p)
    44             {
    45                 printf("%I64d
    ",Q);
    46                 break;
    47             }
    48             Q=po(p/po(1,n-i)-1,n-i);
    49             for(j=n-i;j>=1;j--)
    50             {
    51                 Q=Q+po(9,j-1);
    52             }
    53             if(p-Q<=d)
    54             {
    55                 printf("%I64d
    ",Q);
    56                 break;
    57             }
    58         }
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    Window—mysql下载及安装
    postgresql 在windows下启动调试功能
    FASTREPORT自动换行及行高自适应
    如何卸载已经安装在delphi7中控件包?
    cxgrid使用三问1cxgrid 如何动态创建列2cxGrid 通过字段名取得列3cxGrid动态创建的列里动态创建事件的方法
    VirtualBox中Linux设置共享文件夹
    Android & iOS 启动画面制作工具(转自龟山Aone)
    PostgreSQL 基本数据类型及常用SQL 函数操作
    win10 安装Postgresql 服务不能启动报错
    TdxDbOrgChart 图标显示问题
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771505.html
Copyright © 2011-2022 走看看