zoukankan      html  css  js  c++  java
  • Codeforces Round #427 (Div. 2) B. The number on the board

    引子:

    A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会....

    B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更好一点...

    C题WA第9组,GG思密达....明天起床再补C吧 - -

    题目链接:

    http://codeforces.com/contest/835/problem/B

    B. The number on the board

    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.

    解题思路:

    由于题目过短题意就不说了,其实,具体思路看代码吧!

    AC代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <cmath>
    #include <string.h>
    #include <iostream>
    #include<algorithm>
    #include <queue>
    #include <vector>
    #include <cmath>
    #include<string>
    #define inf 0x3f3f3f3f
    using namespace std;
    const int maxn=1e5+10;
    #define lrt (rt*2)
    #define rrt  (rt*2+1)
    #define LL long long
    #define inf 0x3f3f3f3f
    #define pi acos(-1.0)
    #define exp 1e-8
    #define For(i,n)  for(int i=0;i<n;i++)
    //************************************************63
    char a[maxn];
    LL b[maxn];
    int main()
    {
        LL n,sum=0,k=0,ans=0;
        scanf("%I64d %s",&n,a);
        for(LL i=0;a[i]!='';i++)
        {
            b[k]=a[i]-'0';
            sum+=b[k];
            k++;
        }
        sort(b,b+k);
        while(sum<n)
        {
            sum+=(9-b[ans]);
            ans++;
        }
        cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    python之安卓逆向HOOK系统通用类
    MySQL 排名、分组后组内排名、取各组的前几名
    MySQL case
    MySQL 行列相互转换
    MySQL学习笔记(四)
    回归分析
    构建决策树
    用K-Means聚类分析做客户分群
    会员数据化运营
    数据降维——主成分分析、因子分析、线性判别分析
  • 原文地址:https://www.cnblogs.com/weimeiyuer/p/7266486.html
Copyright © 2011-2022 走看看