zoukankan      html  css  js  c++  java
  • Codeforce 835B

    Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.

    You have to find the minimum number of digits in which these two numbers can differ.

    Input

    The first line contains integer k (1 ≤ k ≤ 109).

    The second line contains integer n (1 ≤ n < 10100000).

    There are no leading zeros in n. It's guaranteed that this situation is possible.

    Output

    Print the minimum number of digits in which the initial number and n can differ.

    Examples
    input
    3
    11
    output
    1
    input
    3
    99
    output
    0
    Note

    In the first example, the initial number could be 12.

    In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

    题解:之前几次都会错题意 哇了好几次 第二天看分类说是贪心 那就贪心吧 每位数字最大到9 如果总和比k小的话 就把差最大的改为9 

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long ll;
    24 ll gcd(ll a,ll b){
    25     return b?gcd(b,a%b):a;
    26 }
    27 const int N=100005;
    28 const int mod=1e9+7;
    29 char a[N];
    30 int main()
    31 {
    32     int k;
    33     scanf("%d",&k);
    34     scanf("%s",&a);
    35     int len=strlen(a);
    36     int s=0;
    37     for(int i=0;i<len;i++){
    38         s+=a[i]-'0';
    39     }
    40     sort(a,a+len);
    41     if(s>=k) cout<<0<<endl;
    42     else {
    43         int t=0;
    44         for(int i=0;i<len;i++){
    45             s+=9-(a[i]-'0');
    46             t++;
    47             if(s>=k){
    48                 break;
    49             }
    50         }
    51         cout<<t<<endl;
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    在没有源代码的情况下调试JAR包..
    Flex游戏篇——游戏开发概述
    CSDN、sina博客在Zoundry中登记的API URL 收藏
    标准博客 API .BLOG APIS
    SAXParseException An invalid XML character 问题的解决
    分布式存储方法
    拨号720错误解决记.txt
    xxx
    硬盘分区后的逻辑结构
    paip sms to blog.txt
  • 原文地址:https://www.cnblogs.com/wydxry/p/7267317.html
Copyright © 2011-2022 走看看