比赛链接: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. LeetCode106 从中序和后序序列构造二叉树

    题目描述: 根据一棵树的中序遍历与后序遍历构造二叉树. 注意:你可以假设树中没有重复的元素. 例如,给出 中序遍历 inorder = [9,3,15,20,7] 后序遍历 postorder = [ ...

  2. 【C++】《C++ Primer 》第五章

    第五章 语句 一.简单语句 表达式语句:一个表达式末尾加上分号,就变成了表达式语句. 空语句:只有一个单独的分号,记得注释说明提高代码可读性. 复合语句(块):用花括号 {}包裹起来的语句和声明的序列 ...

  3. [从源码学设计]蚂蚁金服SOFARegistry之续约和驱逐

    [从源码学设计]蚂蚁金服SOFARegistry之续约和驱逐 目录 [从源码学设计]蚂蚁金服SOFARegistry之续约和驱逐 0x00 摘要 0x01 业务范畴 1.1 失效剔除 1.2 服务续约 ...

  4. 怎么判断innodb 日志缓冲区该设置为多大呢

    怎么判断innodb 日志缓冲区该设置为多大呢

  5. WIN7系统没有USB驱动和以太网驱动如何操作

    |  欢迎关注个人公众号  zclinux_note  第一时间获取关于linux使用的技巧.探索Linux的奥秘   | 今天在单位安装了一台win7纯净版,但是安装完成后发现usb没有反应,插上网 ...

  6. MySQL全面瓦解20:可编程性之流程控制语句

    背景 说到流程控制语句,我们在程序语法中用的比较多,比如C#的if..else...,while...,?: 等.同样的,在MySQL中,也有一些流程控制的语法,方便我们在写函数.存储过程的时候对逻辑 ...

  7. .NET Core使用Source Link提高源代码调试体验和生产效率

    前言: 在我们日常开发过程中常常会使用到很多其他封装好的第三方中间件(NuGet依赖项).类库或者是.NET框架中自带的库.但是当你想要对这些类库的方法设置断点调试,然后发现无法F11(逐语句)调试进 ...

  8. 转 7 jmeter之参数化

    7 jmeter之参数化   badboy里参数化(前面4 jmeter badboy脚本开发技术详解已讲过) jmeter里参数化-1 用户参数 1.打开badboy工具,点击红色按钮开始录制,在地 ...

  9. 前端中的script标签

    script标签中的重要属性! . 浏览器解析行内脚本的方式决定了它在看到字符串时,会将其当成结束的 标签.想避免这个问题,只需要转义字符"\" ①即可: 要包含外部文件中的 Ja ...

  10. 【CentOS7】Apache发布静态网页-超简单

    目前能够提供Web网络服务的程序有 IIS. Nginx和 Apache等.其中,IIS (Internet Information Services,互联网信息服务)是 Windows系统中默认的 ...