VP Educational Codeforces Round 26
A. Text Volume
题意:统计每个单词大写字母个数的最大值。
点击查看代码
void solve() {
int n;
std::cin >> n;
std::string s;
getchar();
std::getline(std::cin, s);
s += " ";
int ans = 0;
for (int i = 0, sum = 0; i <= n; ++ i) {
if (s[i] == ' ') {
ans = std::max(ans, sum);
sum = 0;
} else {
sum += s[i] >= 'A' && s[i] <= 'Z';
}
}
std::cout << ans << "\n";
}
B. Flag of Berland
题意:有三种颜色,判断是不是每种颜色各占一个三分之一大小的矩阵。
模拟题。
点击查看代码
void solve() {
int n, m;
std::cin >> n >> m;
std::vector<std::string> s(n);
for (int i = 0; i < n; ++ i) {
std::cin >> s[i];
}
auto check = [&](int x1, int y1, int x2, int y2, char c) -> bool {
for (int i = x1; i < x2; ++ i) {
for (int j = y1; j < y2; ++ j) {
if (s[i][j] != c) {
return false;
}
}
}
return true;
};
if (n % 3 == 0) {
std::string p = "RGB";
std::vector<int> id{0, 1, 2};
do {
if (check(0, 0, n / 3, m, p[id[0]]) &&
check(n / 3, 0, n / 3 * 2, m, p[id[1]]) &&
check(n / 3 * 2, 0, n, m, p[id[2]])) {
std::cout << "YES\n";
return;
}
} while (std::next_permutation(id.begin(), id.end()));
}
if (m % 3 == 0) {
std::string p = "RGB";
std::vector<int> id{0, 1, 2};
do {
if (check(0, 0, n, m / 3, p[id[0]]) &&
check(0, m / 3, n, m / 3 * 2, p[id[1]]) &&
check(0, m / 3 * 2, n, m, p[id[2]])) {
std::cout << "YES\n";
return;
}
} while (std::next_permutation(id.begin(), id.end()));
}
std::cout << "NO\n";
}
C. Two Seals
题意:一个
也是模拟,我们先把一个和左上角贴齐,然后判断是不是另一个能不能放下就行。枚举两个印章各自旋不旋转,各自放一遍。
点击查看代码
void solve() {
int n, a, b;
std::cin >> n >> a >> b;
std::vector<std::pair<int, int>> c(n);
for (int i = 0; i < n; ++ i) {
std::cin >> c[i].first >> c[i].second;
}
auto check = [&](int h1, int w1, int h2, int w2) -> int {
if (a < h1 || a < h2 || b < w1 || b < w2) {
return 0;
}
if (a - h1 >= h2 || b - w1 >= w2) {
return h1 * w1 + h2 * w2;
}
return 0;
};
int ans = 0;
for (int i = 0; i < n; ++ i) {
auto & [h1, w1] = c[i];
for (int j = i + 1; j < n; ++ j) {
auto & [h2, w2] = c[j];
ans = std::max(ans, check(h1, w1, h2, w2));
ans = std::max(ans, check(w1, h1, h2, w2));
ans = std::max(ans, check(w1, h1, w2, h2));
ans = std::max(ans, check(h1, w1, w2, h2));
}
}
std::cout << ans << "\n";
}
D. Round Subset
题意:
只有质因子
点击查看代码
void solve() {
int n, k;
std::cin >> n >> k;
std::vector<i64> a(n);
for (int i = 0; i < n; ++ i) {
std::cin >> a[i];
}
auto get = [&](i64 x) -> std::pair<int, int> {
int cnt2 = 0, cnt5 = 0;
while (x % 2 == 0) {
++ cnt2;
x /= 2;
}
while (x % 5 == 0) {
++ cnt5;
x /= 5;
}
return {cnt2, cnt5};
};
const int N = n * 26, inf = 1e9;
std::vector f(k + 1, std::vector<int>(N, -inf));
f[0][0] = 0;
int sum5 = 0;
for (int i = 0; i < n; ++ i) {
auto g = f;
auto [cnt2, cnt5] = get(a[i]);
for (int j = 0; j < k; ++ j) {
for (int x = 0; x <= sum5; ++ x) {
g[j + 1][x + cnt5] = std::max(g[j + 1][x + cnt5], f[j][x] + cnt2);
}
}
sum5 += cnt5;
f = g;
}
int ans = 0;
for (int i = 0; i <= sum5; ++ i) {
ans = std::max(ans, std::min(i, f[k][i]));
}
std::cout << ans << "\n";
}
E. Vasya's Function
题意:记
这里
那么我们每次找
点击查看代码
void solve() {
i64 n, m;
std::cin >> n >> m;
std::vector<i64> a;
i64 ans = 0;
while (m > 1) {
i64 min = m;
i64 t = n;
for (i64 i = 2; i * i <= n; ++ i) {
while (t % i == 0) {
min = std::min(min, m % i);
t /= i;
}
}
if (t > 1) {
min = std::min(min, m % t);
}
ans += min;
m -= min;
i64 d = std::gcd(n, m);
n /= d, m /= d;
}
ans += m;
std::cout << ans << "\n";
}
分类:
codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端