首页 > 其他 > 详细

Manthan, Codefest 18 (rated, Div. 1 + Div. 2)

时间:2020-01-29 00:47:30      阅读:81      评论:0      收藏:0      [点我收藏+]

A - Packets

题意:二进制分解

void test_case() {
    int n;
    scanf("%d", &n);
    int x = 1;
    while((1 << x) <= n)
        ++x;
    printf("%d\n", x);
}
int a[200005];

void test_case() {
    int n, s;
    scanf("%d%d", &n, &s);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    int mid = (n + 1) / 2;
    if(a[mid] == s) {
        printf("0\n");
        return;
    } else if(a[mid] > s) {
        ll sum = 0;
        for(int i = 1; i <= mid; ++i) {
            if(a[i] > s)
                sum += a[i] - s;
        }
        printf("%lld\n", sum);
        return;
    } else {
        ll sum = 0;
        for(int i = mid; i <= n; ++i) {
            if(a[i] < s)
                sum += s - a[i];
        }
        printf("%lld\n", sum);
        return;
    }
}
int n;
char s[2000005];
char t[2000005];

void test_case() {
    scanf("%d%s%s", &n, s + 1, t + 1);
    int sum = 0;
    for(int i = 1; i <= n - 1; ++i) {
        if(s[i] != s[i + 1] && s[i] != t[i] && s[i + 1] != t[i + 1]) {
            ++sum;
            swap(s[i], s[i + 1]);
        } else if(s[i] != t[i]) {
            ++sum;
            s[i] = t[i];
        }
    }
    if(s[n] != t[n]) {
        ++sum;
        s[n] = t[n];
    }
    printf("%d\n", sum);
}

Manthan, Codefest 18 (rated, Div. 1 + Div. 2)

原文:https://www.cnblogs.com/KisekiPurin2019/p/12239417.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!