zoukankan      html  css  js  c++  java
  • The number on the board

    B. The number on the board
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    这题比赛的时候一直wa,原来是读错题意了(尴尬)。

    其实读懂题意也是水题一道。

    用了一个vector

     1 #include <bits/stdc++.h>
     2 #define ll long long int
     3 #define M 100005
     4 using namespace std;
     5 char s[M];
     6 vector<int> v;
     7 int main(){
     8     ll a;
     9     scanf("%lld%s",&a,s);
    10     int n=strlen(s);
    11     ll cnt=0;
    12     for(int i=0;i<n;i++){
    13         cnt+=(s[i]-'0');
    14         int f=s[i]-'0';
    15         v.push_back(9-f);
    16     }
    17     sort(v.begin(),v.end());
    18     int ans=0;
    19     while(cnt<a&&v.size()){
    20         a-=v.back();
    21         v.pop_back();
    22         ans++;
    23     }
    24     cout<<ans<<endl;
    25     return 0;
    26 }
  • 相关阅读:
    Beetl 3中文文档 转载 http://ibeetl.com/guide/
    Beetl模板引擎入门教程
    Spring+Stomp+ActiveMq实现websocket长连接
    5672端口引发的一个大坑
    GeoServer中WMS、WFS的请求规范
    常用网址
    JAVA方法参数传递
    针对开发的缺陷管理
    不同逻辑顺序产生相同的结果编码如何决策
    怎样做一个软件项目经理
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7266799.html
Copyright © 2011-2022 走看看