Contest link

质量不错的比赛。

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的更多相关文章

  1. Codeforces Round #204 (Div. 2) A.Jeff and Digits

    因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #204 (Div. 2) C

    写了一记忆化 TLE了  把double换成long long就过了 double 这么耗时间啊 #include <iostream> #include<cstdio> #i ...

  6. Codeforces Round #204 (Div. 2): B

    很简单的一个题: 只需要将他们排一下序,然后判断一下就可以了! 代码: #include<cstdio> #include<algorithm> #define maxn 10 ...

  7. Codeforces Round #204 (Div. 2): A

    超级大水题: 只要用到一个小学用过的结论就可:能被9整除的数它的各位数相加能被9整除: 代码: #include<iostream> #define maxn 1005 using nam ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  9. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  10. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

随机推荐

  1. C++ STL vector 性能之push_back、emplace_back、reserve

    #include <iostream> #include <vector> #include <chrono> using namespace std; const ...

  2. DOM – Event Listener (bubble, capture, passive, custom event)

    前言 老掉牙的东西, 主要是想写 passive, 随便也写一点 bubble, capture 和 custom event 吧. Bubble Dom 监听事件是会冒泡的. 什么意思 ? 上图有 ...

  3. 高通ramdump

    背景 高通平台下提供了一个工具,专门用来抓取内核死机以后的dump信息.如果只是非系统层面的crash(例如底层应用,安卓程序),则不能抓取dump信息. 在阅读一些文档的时候知道有这个功能,但是一直 ...

  4. 封装大屏组件 screenfull

    错误场景:使用大屏插件 screenFull 报错:in ./node_modules/screenfull/index.js  Module parse failed: Unexpected tok ...

  5. 13. 说一下$set,用在Vue2还是Vue3

    $set 是 vue2 中对象用来追加响应式数据的方法 : 使用格式 : $set(对象 , 属性名 , 值 ) vue3中使用 proxy 替代了 Object.defineProperty 实现对 ...

  6. ROS入门21讲(6)

    十.ROS中的坐标系管理系统 1.机器人中的坐标变换 某位姿在A.B两个坐标系下的坐标变换 参考:<机器人学导论> 机器人系统中繁杂的坐标系 2.TF功能包 TF功能包能干什么? ①五秒钟 ...

  7. JS 通过年份获取月,季度,半年度,年度

    原文请关注公众号 "酒酒酒酒"​,关注公众号 回复  "JS 通过年份获取月,季度,半年度,年度" 可获取源代码 功能描述: 实例化一个函数,给函数内传递不同的 ...

  8. CTF-CRYPTO-RSA

    CTF-CRYPTO-RSA 只是个人理解,可能有不正确的地方,具体RSA算法参考:http://8.146.200.37:4100/crypto/asymmetric/rsa 1.RSA算法概述 R ...

  9. HNCTF [Week1]Interesting_http

    <center>HNCTF [Week1]Interesting_http </center> 五毛钱翻译:请用post给我一个 want Burp Suite 抓包传参 &l ...

  10. visual studio当中动态库和静态库的联系

    一.为什么要写这篇博客 公司需要调用MNN框架编译之后的动态库和静态库文件来在另外一台没有编译过MNN框架上的机器运行对应的程序,比如说人体关键点检测之类的程序,这个时候了解静态库和动态库的关系就很有 ...