比赛链接: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. CSS_rules

    CSS 特性 1)控制灵活,功能强大 元素-->标签 针对html的元素 2)可以设置html元素的属性,与html框架的进行分离 3)执行效率更高 CSS语法 text-indent 文字缩进 ...

  2. layui城市三级联动(fesiong / layarea)

    安装 GitHub下载地址:https://github.com/fesiong/layarea.git 使用(html+js) 1. html部分 整个选择器需要使用一个父标签包裹,如下使用了id= ...

  3. JVM-03

    目录 1.1 新生代垃圾收集器 1.1.1 Serial 垃圾收集器(单线程) 1.1.2 ParNew 垃圾收集器(多线程) 1.1.3 Parallel Scavenge 垃圾收集器(多线程) 2 ...

  4. 【SpringBoot1.x】SpringBoot1.x 消息

    SpringBoot1.x 消息 文章源码 概述 大多应用中,可通过消息服务中间件来提升系统异步通信.扩展解耦能力. 消息服务有两个重要概念,即消息代理(message broker)和目的地(des ...

  5. SwiftUI 官方画图实例详细解析

    前言 在前面几篇关于SwiftUI的文章中,我们用一个具体的基本项目Demo来学习了下SwiftUI,里面包含了常见的一些控件使用以及数据处理和地图等等,有兴趣的小伙伴可以去翻翻以前的文章,在前面总结 ...

  6. Os-hackNos-特权文件提权

    一 信息收集 netdiscover -i eth0 -r 10.10.10.0/24 扫描ip nmap -sP 192.168.43.0/24 扫描开放的端口 使用"-sP"选 ...

  7. [WPF] 在单元测试中使用 Prism 的 EventAggregator,订阅到 ThreadOption.UIThread 会报错

    1. 问题 [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { ContainerLocator ...

  8. eCATT使用前的配置

    如果想在SAP中使用eCATT,必须做一下相关的配置才行,下面简单介绍这几步:1.SM30,输入表T000,然后点击维护,或者是进入事物SCC4,进入对应的clint属性编辑视图下,将CATT and ...

  9. ModelForm的基本用法:

    一.ModelForm的基本用法示例: from django import forms from app01 import models class BookModelForm(forms.Mode ...

  10. 关于Java客户端连接虚拟机中的Kafka时,无法发送、接收消息的问题

    kafka通过控制台模拟消息发送和消息接收正常,但是通过javaAPI操作生产者发送消息不成功 消费者接收不到数据解决方案? 1.问题排查 (1)首先通过在服务器上使用命令行来模拟生产.消费数据,发现 ...