zoukankan      html  css  js  c++  java
  • Codeforces Round 427 B The name on the board 水题

      题目链接: http://codeforces.com/contest/835/problem/B

      题目描述: 一个数原来的和至少K,再给出一个数问最少改变几位可以得到原来那个数  

      解题思路:  水题

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iterator>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <deque>
    #include <map>
    #define lson l, m, rt<<1
    #define rson m+1, r, rt<<1|1
    #define mem0(a) memset(a,0,sizeof(a))
    #define meminf(a) memset(a,0x3f,sizeof(a))
    using namespace std;
    
    const int maxn = 1e6 + 100;
    char a[maxn];
    int s[maxn];
    
    int main() {
        memset(s, 0, sizeof(s));
        int k;
        scanf( "%d%s", &k, a );
        int len = (int)strlen(a);
        for( int i = 0; i < len; i++ ) {
            s[i] = (int)a[i]-48;
        }
        //    for( int i = 0; i <len; i++ ) {
        //        cout << s[i] << endl;
        //    }
        int sum = 0;
        for( int i = 0; i < len; i++ ) {
            sum += s[i];
    //        cout << s[i] << endl;
        }
        //    cout << sum << endl;
        if( sum >= k ) {
            printf( "0
    " );
            return 0;
        }
        else {
            sort(s, s+len);
            int ans = 0;
            while( sum < k ) {
    //            cout << sum << endl;
                sum += (9-s[ans]);
                ans++;
            }
            cout << ans << endl;
    
        }
        return 0;
    }
    View Code

      思考: 一道水题, 不应该写到博客上的......算了都写这么多了, 以后不写这种题了

  • 相关阅读:
    Lyft Level 5 Challenge 2018
    Codeforces Round #514 (Div. 2)题解
    Bubble Cup 11
    不如来搞一下CDQ分治吧!
    Codeforces Round #331 (Div. 2)
    写一下中国剩余定理的证明
    codeforces Round#332Div2 题解
    GCPC2017 题解
    2017 USP Try-outs 题解
    CodeForce 387D. George and Interesting Graph
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7356818.html
Copyright © 2011-2022 走看看