【codeforces】Codeforces Round #643 (Div. 2)

套题传送门

A. Sequence with Digits

【模拟】纸老虎...按照规则模拟,当\(minDigit(a_i)=0\)时退出模拟。

B. Young Explorers

【贪心】\(e_i\)的意思是若该队员想要组队,队内至少有\(e_i\)名成员(包括他自己)才能出发。一些人也可以不组队。

按照\(e_i\)小到大组队。当前最大\(e_i\)值都满足了之后,就可以组成一支新队。

有桶排的味道,但这里桶排被TLE了(亲测quq)

D. Game With Array

【构造】Petya有一个数组有\(N\)个数字,它们的和为\(S\)。Vasya要从这个数组里取一些数并对其求和,Vasya的总和等于\(K\)或者\(S-K\),则是Vasya获胜。(\(K\)为Petya给定的一个不大于\(K\)的数)现在如何构造这个\(N\)个数的数组以及\(K\),才能让Vasya不能获胜。

仔细想想可以发现,Petya的获胜的条件就是,数组里的数不能完全组合成[1,S]。而构造这种,一般从1开始找就很舒服了。

\(N > S / 2\)时,Vasya必胜;

\(S\)为偶数时,前\(N-1\)个数为1,第\(N\)个数为\(S-(N-1)\)。这样,原数组的数不能组合成\(S/2\)

\(S\)为奇数时,前\(N-1\)个数为1,第\(N\)个数为\(S-(N-1)\)。这样,原数组的数不能组合成\(S/2\)\(S/2 + 1\)


AC代码

A

//
#include<iostream>
#include<cstdio>
using namespace std;

typedef long long LL;
int T;
LL a, k;

int main()
{
    scanf("%d", &T);
    while(T--){
        scanf("%I64d %I64d", &a, &k);
        for(LL i = 1; i < k; i++){
            LL tmp = a;
            LL x = 20, d = -1;
            while(tmp){
                if(tmp % 10 < x) x = tmp % 10;
                if(tmp % 10 > d) d = tmp % 10;
                tmp /= 10;
            }
            if(x == 0 || d == 0)
                break;
//            printf("a:%I64d x:%I64d d:%I64d\n", a, x, d);
            a += x * d;
        }
        printf("%I64d\n", a);
    }
    return 0;
}

B

//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int T, n;
int num[200005];

int main()
{
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        for(int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }

        sort(num, num + n);

        int cnt = 0, big = 0, ans = 0;
        for(int i = 0; i < n; i++){
            if(big < num[i]) big = num[i];
            cnt++;
            if(cnt / big > 0) {
                ans += cnt / big;
                cnt %= big;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

D

//
#include<iostream>
#include<cstdio>
using namespace std;

int n, s;
int num[1000006];

int main()
{
    scanf("%d %d", &n, &s);
    if(n > s / 2) printf("NO\n");
    else {
        printf("YES\n");
        for(int i = 0; i < n - 1; i++){
            printf("1 ");
        }
        printf("%d\n", s - (n - 1));
        printf("%d\n", s / 2);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Ayanowww/p/12904192.html