Codeforces Round #796 (Div. 2)

2022-06-04 02:03:19  阅读：187  来源： 互联网

AC代码
// Problem: A. Cirno's Perfect Bitmasks Classroom
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//

#include <bits/stdc++.h>

#define CPPIO std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
#define freep(p) p ? delete p, p = nullptr, void(1) : void(0)

#ifdef BACKLIGHT
#include "debug.h"
#else
#define logd(...) ;
#endif

using i64 = int64_t;
using u64 = uint64_t;

void solve_case(int Case);

int main(int argc, char* argv[]) {
CPPIO;
int T = 1;
std::cin >> T;
for (int t = 1; t <= T; ++t) {
solve_case(t);
}
return 0;
}

void solve_case(int Case) {
int x, y;
std::cin >> x;
y = (x & -x);
if (x == y) {
if (x == 1)
y += 2;
else
y += 1;
}
std::cout << y << "\n";
}



B. Patchouli's Magical Talisman

1. 从$$a$$中选择两个数$$a_i$$和$$a_j$$，将这两个数从$$a$$中删除，然后再向$$a$$中插入$$a_i + a_j$$。
2. 从$$a$$中选择一个偶数$$x$$，将其替换成$$\frac{x}{2}$$。

$$a$$中没有偶数，答案为零。

AC代码
// Problem: B. Patchouli's Magical Talisman
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//

#include <bits/stdc++.h>

#define CPPIO std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
#define freep(p) p ? delete p, p = nullptr, void(1) : void(0)

#ifdef BACKLIGHT
#include "debug.h"
#else
#define logd(...) ;
#endif

using i64 = int64_t;
using u64 = uint64_t;

void solve_case(int Case);

int main(int argc, char* argv[]) {
CPPIO;
int T = 1;
std::cin >> T;
for (int t = 1; t <= T; ++t) {
solve_case(t);
}
return 0;
}

void solve_case(int Case) {
int n;
std::cin >> n;

int mi = INT_MAX;
int c0 = 0, c1 = 0;
for (int i = 0; i < n; ++i) {
int x;
std::cin >> x;

if (x % 2 == 0)
++c0;
else
++c1;

int t = 0;
while (x % 2 == 0) {
++t;
x = x / 2;
}
if (t != 0)
mi = std::min(mi, t);
}

if (c0 == 0)
std::cout << "0\n";
else if (c1 != 0)
std::cout << c0 << "\n";
else
std::cout << mi + n - 1 << "\n";
}



C. Manipulating History

$$t$$和$$s_n$$中的所有字符，只有初始字符会出现奇数次，所以统计字符出现的次数，出现奇数次的那个就是答案。

AC代码
// Problem: C. Manipulating History
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//

#include <bits/stdc++.h>

#define CPPIO std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
#define freep(p) p ? delete p, p = nullptr, void(1) : void(0)

#ifdef BACKLIGHT
#include "debug.h"
#else
#define logd(...) ;
#endif

using i64 = int64_t;
using u64 = uint64_t;

void solve_case(int Case);

int main(int argc, char* argv[]) {
CPPIO;
int T = 1;
std::cin >> T;
for (int t = 1; t <= T; ++t) {
solve_case(t);
}
return 0;
}

void solve_case(int Case) {
int n;
std::cin >> n;

std::vector<int> c(26, 0);
for (int i = 0; i <= 2 * n; ++i) {
std::string s;
std::cin >> s;
for (char ch : s) {
++c[ch - 'a'];
}
}
logd(c);

char ans = '?';
for (int i = 0; i < 26; ++i) {
if (c[i] & 1) {
if (ans == '?') {
ans = i + 'a';
} else {
assert(false);
}
}
}
std::cout << ans << "\n";
}



D. The Enchanted Forest

AC代码
// Problem: D. The Enchanted Forest
// Contest: Codeforces - Codeforces Round #796 (Div. 2)
// URL: https://codeforces.com/contest/1688/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//

#include <bits/stdc++.h>

#define CPPIO std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
#define freep(p) p ? delete p, p = nullptr, void(1) : void(0)

#ifdef BACKLIGHT
#include "debug.h"
#else
#define logd(...) ;
#endif

using i64 = int64_t;
using u64 = uint64_t;

void solve_case(int Case);

int main(int argc, char* argv[]) {
CPPIO;
int T = 1;
std::cin >> T;
for (int t = 1; t <= T; ++t) {
solve_case(t);
}
return 0;
}

void solve_case(int Case) {
int n, k;
std::cin >> n >> k;

std::vector<i64> a(n + 1);
for (int i = 1; i <= n; ++i)
std::cin >> a[i];

if (n == 1) {
i64 ans = a[1] + k - 1;
std::cout << ans << "\n";
return;
}

std::vector<i64> b(n + 1);
for (int i = 1; i <= n; ++i)
b[i] = b[i - 1] + a[i];

i64 ans = 0;
if (k < n) {
i64 ma = 0;
for (int i = k; i <= n; ++i)
ma = std::max(ma, b[i] - b[i - k]);
ans += ma;
ans += i64(1) * (k - 1) * k / 2;
} else {
ans += b[n];
ans += i64(1) * (n - 1) * n / 2;
k -= n;
ans += i64(1) * k * n;
}

std::cout << ans << "\n";
}



TBA。

TBA。