Manthan, Codefest 18 (rated, Div. 1 + Div. 2)
Posted kisekipurin2019
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Manthan, Codefest 18 (rated, Div. 1 + Div. 2)相关的知识,希望对你有一定的参考价值。
A - Packets
题意:二进制分解
void test_case() {
int n;
scanf("%d", &n);
int x = 1;
while((1 << x) <= n)
++x;
printf("%d
", 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
");
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
", sum);
return;
} else {
ll sum = 0;
for(int i = mid; i <= n; ++i) {
if(a[i] < s)
sum += s - a[i];
}
printf("%lld
", 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
", sum);
}
以上是关于Manthan, Codefest 18 (rated, Div. 1 + Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章
题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造