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

▼魔方 西西 提交于 2020-01-29 01:01:02

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);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!