比赛链接:https://codeforces.com/contest/1443

A. Kids Seating

题意

构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数小于 \(4n\) 。

题解

因为不互质所以 \(gcd\) 至少为 \(2\),又为了避免相互整除,可以从倒着较大的 \(4n\) 开始构造。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v;
for (int i = 4 * n; int(v.size()) < n; i -= 2) {
v.push_back(i);
}
for (int i = 0; i < n; i++) {
cout << v[i] << " \n"[i == n - 1];
}
}
return 0;
}

B. Saving the City

题意

给出一个 \(01\) 串,有两种操作:

  • 消除一段连续的 \(1\),花费为 \(a\)
  • 将一个 \(0\) 变为 \(1\),花费为 \(b\)

问将字符串全变为 \(0\) 的最小花费是多少。

题解

记录所有连续 \(1\) 区间的左右端点,然后尝试合并相邻区间。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
string s;
cin >> s;
int n = s.size();
vector<pair<int, int>> v;
for (int i = 0; i < n; ) {
int j = i + 1;
if (s[i] == '1') {
while (j < n and s[j] == '1') ++j;
v.emplace_back(i, j);
}
i = j;
}
int ans = v.size() * a;
for (int i = 1; i < int(v.size()); i++) {
auto [l1, r1] = v[i - 1];
auto [l2, r2] = v[i];
if ((l2 - r1) * b <= a) {
ans -= a - (l2 - r1) * b;
}
}
cout << ans << "\n";
}
return 0;
}

C. The Delivery Dilemma

题意

给出 \(n\) 份食物外送和自取需要的时间,外送是同时开始的,自取需要依次进行,问最少要花费多少时间才能取到所有食物。

题解

将食物按照外送时间从小到大排序,计算自取时间的后缀和,从前向后枚举外送食物的最大时间,取与后缀和之和的最小值即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<pair<int, int>> v(n);
for (auto &[x, y] : v) cin >> x;
for (auto &[x, y] : v) cin >> y;
sort(v.begin(), v.end());
vector<long long> suf(n + 1);
for (int i = n - 1; i >= 0; i--) {
suf[i] = suf[i + 1] + v[i].second;
}
long long ans = 0;
for (auto [x, y] : v) ans += y;
for (int i = 0; i < n; i++) {
ans = min(ans, max(v[i].first * 1LL, suf[i + 1]));
}
cout << ans << "\n";
}
return 0;
}

D. Extreme Subtraction

题意

给出一个大小为 \(n\) 的数组 \(a\),每次操作有两种选择:

  • 取最左端的一段连续区间,将区间内的数全部减一
  • 取最右端的一段连续区间,将区间内的数全部减一

判断能否使所有数都变为 \(0\) 。

题解

如果一个数大于它右边的数,那么它及左端的数一定要连续减差值次,判断是否有数最终减的次数大于原值即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto &x : a) cin >> x;
for (int i = n - 2; i >= 0; i--) {
if (a[i] > a[i + 1]) {
for (int j = 0; j <= i; j++) a[j] -= a[i] - a[i + 1];
}
}
cout << (any_of(a.begin(), a.end(), [](int x) { return x < 0; }) ? "NO" : "YES") << "\n";
}
return 0;
}

F. Identify the Operations

题意

给出一个大小为 \(n\) 的排列,每次操作可以删除 \(a_{i-1}\) 或 \(a_{i+1}\) 来选取 \(a_i\),给出最终选取的序列,计算可以得到该序列的方案数。

题解

存储每个值的位置,并在一开始删除所有在最终序列中的数的位置,每次选取后再将该位置存入。

代码

#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> pos(n);
set<int> st;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
--x;
pos[x] = i;
st.insert(pos[x]);
}
vector<int> b(k);
for (auto &x : b) {
cin >> x;
--x;
st.erase(pos[x]);
}
long long ans = 1;
for (auto x : b) {
ans = ans * (st.count(pos[x] - 1) + st.count(pos[x] + 1)) % MOD;
st.insert(pos[x]);
}
cout << ans << "\n";
}
return 0;
}

Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】的更多相关文章

  1. Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)

    题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...

  2. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) D. Extreme Subtraction (贪心)

    题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解: ...

  3. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)

    题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...

  4. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) B. Saving the City (贪心,模拟)

    题意:给你一个\(01\)串,需要将所有的\(1\)给炸掉,每次炸都可以将一整个\(1\)的联通块炸掉,每炸一次消耗\(a\),可以将\(0\)转化为\(1\),消耗\(b\),问将所有\(1\)都炸 ...

  5. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) A. Kids Seating (规律)

    题意:给你一个正整数\(n\),在\([1,4n]\)中找出\(n\)个数,使得这\(n\)个数中的任意两个数不互质且不能两两整除. 题解:这题我是找的规律,从\(4n\)开始,往前取\(n\)个偶数 ...

  6. Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations

    VK news recommendation system daily selects interesting publications of one of n disjoint categories ...

  7. Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp( ...

  8. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

    A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...

  9. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring

    C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandar ...

随机推荐

  1. vue的favicon.ico的不能修改替换问题解决。

    vue的favicon.ico解决办法: 暴力替换图片: <link rel="icon" href="favicon.ico" type="i ...

  2. 知识图谱和neo4j的基本操作

    一.知识图谱的简介 1.知识图谱是什么 知识图谱本质上是语义网络(Semantic Network)的知识库 可以理解为一个关系图网络. 2.什么是图 图(Graph)是由节点(Vertex)和边(E ...

  3. 请求接口获取的json 字符串 前后不能有 双引号

    请求接口获取的json 字符串 前后不能有 双引号 否则JSON.parse 转换会报错

  4. 【MySQL】Last_SQL_Errno: 1594Relay log read failure: Could not parse relay log event entry...问题总结处理

    备库报错: Last_SQL_Errno: 1594 Last_SQL_Error: Relay log read failure: Could not parse relay log event e ...

  5. kubectl命令管理

    kubectl命令管理 查看更多帮助命令 [root@k8s-master ~]# kubectl --help 创建一个命名空间 [root@k8s-master ~]# kubectl creat ...

  6. 深度解读设备的“万能语言”HarmonyOS的分布式软总线能力

    摘要:本文分享鸿蒙分布式软总线,并对相关源代码进行解析,为在鸿蒙系统平台上工作的相关人员的信息参考和指导. 总线是一种内部结构,在计算机系统中,主机的各个部件通过总线相连,外部设备通过相应的接口电路再 ...

  7. 学习Java第三天

    方法重载:同一个类,方法名相同,参数不同(个数不同,类型不同,顺序不同),判断是否重载,只看方法名和参数,跟返回值无关. IDEA查看方法源代码:Crtl + 鼠标左键 进制表示 Java数值默认为十 ...

  8. 【MYSQL】DDL语句

    介绍:DDL语句,即数据定义语句,定义了不同的数据段,数据库表.表.列.索引等数据库对象:例如,create.drop.alter 适用对象:一般是由数据库管理员DBA使用 1.连接数据库 mysql ...

  9. Spring Security,没有看起来那么复杂(附源码)

    权限管理是每个项目必备的功能,只是各自要求的复杂程度不同,简单的项目可能一个 Filter 或 Interceptor 就解决了,复杂一点的就可能会引入安全框架,如 Shiro, Spring Sec ...

  10. js input相关事件(转载)

    1.onfocus  当input 获取到焦点时触发. 2.onblur  当input失去焦点时触发,注意:这个事件触发的前提是已经获取了焦点再失去焦点的时候才会触发该事件,用于判断标签为空.3.o ...