zoukankan      html  css  js  c++  java
  • Codeforces Round #643 (Div. 2)

    题目传送门

    A. Sequence with Digits

    an+1=an+minDigit(an)maxDigit(an),已知a1,k,求ak。

    当minDigit(an)=0时,an+1=an,对后续的答案不会产生影响了。

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
    
    ll a, k;
    
    void solve()
    {
        cin >> a >> k;
        while (--k)
        {
            ll x = 9, y = 0;
            for (ll tmp = a; tmp; tmp /= 10)
            {
                x = min(x, tmp % 10);
                y = max(y, tmp % 10);
            }
            if (x == 0)
                break;
            a += x * y;
        }
        cout << a << endl;
    }
    
    int main()
    {
        int t = 1;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    View Code

    B. Young Explorers

    第i个人能存在于人数大于等于ei的队伍,求最大队伍数。

    贪心,将e数组排个序,从小到大进行分组。

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
    
    ll n, e[200010];
    
    void solve()
    {
        cin >> n;
        rep(i, 1, n) cin >> e[i];
        sort(e + 1, e + n + 1);
        int tmp = 0, ans = 0;
        rep(i, 1, n)
        {
            tmp++;
            if (tmp >= e[i])
            {
                ans++;
                tmp = 0;
            }
        }
        cout << ans << endl;
    }
    
    int main()
    {
        int t = 1;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    View Code

    C. Count Triangles

    a<=x<=b<=y<=c<=z<=d,x,y,z能构成三角形的个数。

    首先,暴力

    rep(x, a, b) rep(y, b, c) rep(z, c, d) if (x + y > z) ans++;

    优化至二维,x+y>d时,y就没有必要再往大遍历

    rep(x, a, b) rep(y, b, c)
    {
        if (x + y > d)
        {
            ans += (c - y + 1) * (d - c + 1);
            break;
        }
        if (x + y > c)
            ans += x + y - c;
    }

    再往下我就不会了。。( ´◔ ‸◔`)

    D. Game With Array

    构造一个元素和为s,长度为n的数组,以及k,使非空子数组的和不为s-k和k。

    类似1,1,1,,,1,s-n+1构造,如果s-n+1>2,前n-1项和一定不为n。然后就判断下(s-n+1)是否大于n。(特判一下n==1,s==2)

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
     
    ll n, s;
    void solve()
    {
        cin >> n >> s;
        if (n == 1 && s == 2)
            puts("YES
    2
    1");
        else if (s - n <= 1 || s + 1 <= 2 * n)
            puts("NO");
        else
        {
            puts("YES");
            rep(i, 1, n - 1) cout << "1 ";
            cout << s - n + 1 << endl
                 << n;
        }
    }
     
    int main()
    {
        int t = 1;
        // cin >> t;
        while (t--)
        {
            solve();
        }
    }
    View Code
  • 相关阅读:
    codevs 1102 采药 2005年NOIP全国联赛普及组
    codevs 1058 合唱队形 2004年NOIP全国联赛提高组
    动归题目
    友好城市//未测,不知对错
    codevs 1044 拦截导弹 1999年NOIP全国联赛提高组
    codevs 5294 挖地雷
    codevs 1576 最长严格上升子序列
    [BZOJ3289]Mato的文件管理
    [CodeVS1299]切水果
    [TYVJ1473]校门外的树3
  • 原文地址:https://www.cnblogs.com/likunhong/p/12909669.html
Copyright © 2011-2022 走看看