AtCoder Beginner Contest 101 完整

作者: 海天一树X | 来源:发表于2018-06-24 19:21 被阅读14次

    A题

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        string s;
        cin >> s;
        int cnt1 = 0, cnt2 = 0;
        for(int i = 0; i < 4; i++)
        {
            if('+' == s[i])
            {
                cnt1++;
            }
            else
            {
                cnt2++;
            }
        }
    
        cout << cnt1 - cnt2;
        return 0;
    }
    

    B题

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int num;
        cin >> num;
        int temp = num;
    
        int n = 0;
        while(temp)
        {
            n += temp % 10;
            temp /= 10;
        }
    
        if(0 == num % n)
        {
            cout << "Yes";
        }
        else
        {
            cout << "No";
        }
    }
    

    C题

    分析:因为最小的数为1,最终所有的数必然全变为1。计算1左边和右边的数各分为多少段,加起来即可得到结果。
    假设1位于第i个位置,则左边的分段为(i - 1) / (k - 1),右边的分段为(n - i) / (k - 1),
    加起来(i - 1) / (k - 1) + (n - i) / (k - 1) = (n - 1) / (k - 1)

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int n, k;
        cin >> n >> k;
        int a[n + 1];
        for(int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
    
        int ans = (n - 1) / (k - 1);
        if(0 != (n - 1) % (k - 1))
        {
            ans += 1;
        }
    
        cout << ans;
    
        return 0;
    }
    

    D题

    官方题解:
    https://img.atcoder.jp/arc099/editorial.pdf

    #include<iostream>
    using namespace std;
    
    typedef long long LL;
    
    double s(LL n)
    {
        LL x = n;
        LL y = 0;
        while (x)
        {
            y += x % 10;
            x /= 10;
        }
    
        return (double)n / y;
    }
    
    int main()
    {
        LL K;
        LL n = 1;
        LL x = 1;
    
        cin >> K;
    
        for (int i = 0; i < K; i++)
        {
            cout << n << endl;
            if (s(n + x) > s(n + x * 10))
            {
                x *= 10;
            }
    
            n += x;
        }
    
        return 0;
    }
    

    TopCoder & Codeforces & AtCoder交流QQ群:648202993
    更多内容请关注微信公众号


    wechat_public_header.jpg

    相关文章

      网友评论

        本文标题:AtCoder Beginner Contest 101 完整

        本文链接:https://www.haomeiwen.com/subject/rtesyftx.html