LGR-204-Div.2
质量不错的比赛。
A
比较明显的题,贪心往下做就可以。
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 1e5 + 7;
int k;
int a[N];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> k;
for (int i = 1; i <= k; i++) {
std::cin >> a[i];
}
if (k == 1 && a[1] == 1) { std::cout << "1\n"; exit(0); }
std::sort(a + 1, a + k + 1);
int dep = 1, ans = 1;
for (int i = 1; i <= k; i++) {
ans += (a[i] - dep);
dep = a[i] - 1;
}
std::cout << ans << "\n";
return 0;
}
B
比较明显的题,模拟一下往下做就可以。
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n;
std::string s;
std::cin >> n >> s;
int cnt = 1;
std::vector<int> a(n + 1);
if (s[0] == '=')
cnt = 2;
else
a[1] = 1;
char lst = s[0];
for (int i = 1; i < n - 1; i++) {
if (s[i] == '=') {
a[i + 1] = a[i];
cnt++;
}
else if (s[i] == s[i - 1]) {
a[i + 1] = a[i] + 1;
cnt = 1;
}
else if (s[i] != lst) {
a[i + 1] = cnt;
cnt = 1;
lst = s[i];
}
else if (s[i] == lst) {
a[i + 1] = a[i] + cnt;
cnt = 1;
}
}
i64 ans = 0;
for (int i = 0; i <= n; i++)
ans += a[i];
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
C
观察到 \(m \leq 20\) 肯定不对劲,并且好像没有什么现成的方便的 DS 可以快速维护两序列区间排序并,注意到是一个诈骗题,直觉能够感受到在在不多次操作之后整个序列会趋向有序,这时可以直接考虑 swap() 掉,否则就暴力修改插入,然后发现这样是对的,可以证明最多只需要 \(O(m^2)\) 次操作,似乎是 \(\frac{m(m - 1)}{2}\)?
注意到它卡输入。
以后非必要没弄懂就不要乱解地址,你搞不明白,而且你 CSP 2024 已经炸了一次 set*。
#include <bits/stdc++.h>
using i64 = long long;
template <typename T> T read() {
T sum = 0, fl = 1;
int ch = getchar_unlocked();
for (; !isdigit(ch); ch = getchar_unlocked()) { if (ch == '-') fl = -1; }
for (; isdigit(ch); ch = getchar_unlocked()) sum = sum * 10 + ch - '0';
return sum * fl;
}
template <typename T> void write(T x) {
if (x < 0) { x = -x; putchar_unlocked('-'); }
if (x > 9) write(x / 10);
putchar_unlocked(x % 10 + '0');
}
void solve() {
int n = read<int>(), m = read<int>(), q = read<int>();
std::vector<int> G[m + 1];
std::vector<bool> vis(m + 1);
for (int x = 1; x <= m; x++) {
for (int i = 1, p; i <= n; i++) {
p = read<int>();
G[x].push_back(p);
}
}
while (q--) {
int opt = read<int>(), x = read<int>(), y = read<int>();
if (opt == 2) {
write<int>(G[x][y - 1]);
puts("");
} else {
if (vis[x] && vis[y]) {
/*if (*G[x].end() <= *G[y].begin())
continue;
if (*G[y].end() <= *G[x].begin()) {
std::swap(G[x], G[y]);
continue;
}*/
if (G[x][G[x].size() - 1] <= G[y][0])
continue;
if (G[y][G[y].size() - 1] <= G[x][0]) {
std::swap(G[x], G[y]);
continue;
}
}
std::vector<int> v;
v.insert(v.end(), G[x].begin(), G[x].end());
v.insert(v.end(), G[y].begin(), G[y].end());
std::sort(v.begin(), v.end());
for (int i = 0; i < n; i++)
G[x][i] = v[i];
for (int i = n; i < v.size(); i++)
G[y][i - n] = v[i];
vis[x] = vis[y] = 1;
}
}
}
int main() {
// std::ios::sync_with_stdio(false);
// std::cin.tie(nullptr);
solve();
return 0;
}
D
试判断是否存在一个 \(n\) 个 \(0\) 和 \(m\) 个 \(1\) 的 \(01\) 串满足对于任意一个长度 \([2L, 2R]\) 的子串,其 \(n\) 和 \(m\) 的数量不相等
学习了一个新的 trick。
对于 \(01\) 串个数相等的问题,可以考虑将其转到二维平面上走网格,选择一个 \(1\) 表示向下走一格,选择一个 \(0\) 表示向下走一格。
这样子做的话我们就成功转化了题面:从 \((m, n)\) 往 \((0, 0)\) 走,走到 \((0, 0)\),每一次移动都会新产生几个障碍,求是否存在一条路径使其不经过障碍。
这样子看起来就可做了很多。
发现障碍的位置是随着移动的位置而平移的,贪心地贴着障碍边界往下走,如果最后障碍的边界与 \(x\) 轴的交点 \(\gt 0\) 就可行。
通过打表找一下周期,特殊处理 \(x\) 轴附近的点就解决问题了。
corner case 好像小多。
周期的探讨还是看 原的 Solution 比较好,照搬过来没什么意思。
好题。
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
void solve() {
u64 l, r, m, n;
std::cin >> l >> r >> m >> n;
if (!n || !m) {
std::cout << "Yes\n";
return;
}
if (l == 1) {
std::cout << "No\n";
return;
}
if (n > m) {
std::swap(n, m);
}
u64 a = (n - 1) / (l - 1);
u64 b = n - a * (l - 1);
u64 c = a * (l + 1) + std::min(b - 1, a * (r - l));
if (c <= m)
std::cout << "Yes\n";
else
std::cout << "No\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
LGR-204-Div.2的更多相关文章
- Codeforces Round #204 (Div. 2) A.Jeff and Digits
因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...
- Codeforces Round #204 (Div. 2)->D. Jeff and Furik
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #204 (Div. 2)->C. Jeff and Rounding
C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #204 (Div. 2)->B. Jeff and Periods
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #204 (Div. 2) C
写了一记忆化 TLE了 把double换成long long就过了 double 这么耗时间啊 #include <iostream> #include<cstdio> #i ...
- Codeforces Round #204 (Div. 2): B
很简单的一个题: 只需要将他们排一下序,然后判断一下就可以了! 代码: #include<cstdio> #include<algorithm> #define maxn 10 ...
- Codeforces Round #204 (Div. 2): A
超级大水题: 只要用到一个小学用过的结论就可:能被9整除的数它的各位数相加能被9整除: 代码: #include<iostream> #define maxn 1005 using nam ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
随机推荐
- Email 关于 POP3 IMAP SMTP office365 Outlook Gmail G-Suit shared mailbox小小理解
Outlook 是微软的一个 email 软件, 管理 email 的 UI. Gmail 是 google 的 office365 是一个配套, 里面有 email, one drive, exce ...
- OData – Query to Expression
前言 EF Core 可以把 expression 转换成 string, 但没办法转回来. 想把 string 转成 expression, 目前最合适的工具是 OData. 虽然 Dynamic ...
- 这10种分布式ID,太绝了!
前言 分布式ID,在我们日常的开发中,其实使用的挺多的. 有很多业务场景在用,比如: 分布式链路系统的trace_id 单表中的主键 Redis中分布式锁的key 分库分表后表的id 今天跟大家一起聊 ...
- QT6新旧版本功能模块对比:QT6做了哪些优化重组?QT6新增加了哪些功能模块?QT6做了哪些改进、提升和优化?
简介 本文介绍了QT6新旧版本都有的功能模块.QT6优化掉了或转移了的功能模块.QT6新增加的功能模块,以及QT6做了哪些改进.提升和优化. 文章目录 QT6新旧版本都有的功能模块 QT6优化掉了或转 ...
- 还在苦于密码太弱?教你3招用Linux生成高强度密码
各位好啊,我是会编程的蜗牛,作为java开发者,我们平常肯定会接触Linux操作系统,其实除了一般的部署应用外,它还可以帮助我们生成密码.解决我们平常自己想各种复杂密码的烦恼,以后我会讲一讲如何安全地 ...
- 官方 | 征集 Flutter 桌面端应用程序的构建案例
亲爱的社区成员们,大家好! Google Flutter 团队希望了解开发者们使用 Flutter 构建的桌面端应用程序,以提高 Flutter 桌面端的测试覆盖率,邀请大家通过表单的形式提交征集和反 ...
- 获取form提交的返回值
获取form提交的返回值 HTML代码如下: <form action="" method="post" enctype="multipart/ ...
- linux那些事之页迁移(page migratiom)
Page migration 页迁移技术是内核中内存管理的一种比较重要的技术,最早该技术诞生于NUMA系统中(Page migration [LWN.net]),后续由于内存规整以及CMA和COW技术 ...
- maven的pom.xml基础配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- Android复习(二)应用资源
1. res下的资源类型 目录 资源类型 animator/ 用于定义属性动画的 XML 文件. anim/ 用于定义渐变动画的 XML 文件.(属性动画也可保存在此目录中,但为了区分这两种类型,属性 ...