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); }
来源:https://www.cnblogs.com/KisekiPurin2019/p/12239417.html