比赛链接: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. 深入浅出Dotnet Core的项目结构变化

    有时候,越是基础的东西,越是有人不明白.   前几天Review一个项目的代码,发现非常基础的内容,也会有人理解出错. 今天,就着这个点,写一下Dotnet Core的主要类型的项目结构,以及之间的转 ...

  2. mmall商城购物车模块总结

    购物车模块的设计思想 购物车的实现方式有很多,但是最常见的就三种:Cookie,Session,数据库.三种方法各有优劣,适合的场景各不相同.Cookie方法:通过把购物车中的商品数据写入Cookie ...

  3. 通用寄存器_MOV_ADD_SUB_AND_OR_NOT

    通用寄存器 MOV指令 注意:目标操作数与操作数宽度必须一样 MOV 目标操作数,源操作数 作用:拷贝源操作数到目标操作数 1.源操作数可以是立即数.通用寄存器.段寄存器.或者内存单元. 2.目标操作 ...

  4. 修改机器的hostname

    vi /etc/sysconfig/network hostname=你想设置的主机名 不重启器的情况下使显示名称变成 hostname  主机名

  5. K8s遇到问题解决思路

    问题排查一 从describe去查找相应的deploy/pod/rs/svc [root@k8s-master ~]# kubectl describe po/nginx-f95d765f9-8b6b ...

  6. Oracle备份审计表SYS.AUD$和SYS.FGA_LOG$

    ORACLE的审计表不可以使用expdp和impdp导出和导入,如果使用,会报如下错误: 需要使用exp和imp进行导出和导出 导出语句: exp " '/ as sysdba' " ...

  7. python异步回调顺序?是否加锁?

    话不多说,直接上代码: import time from functools import partial from concurrent.futures.process import Process ...

  8. 使用gui_upload的总结

    今天使用gui_upload函数将文本文件的内容读取到内表.出现了一个问题,总是程序宕掉,出项的提示是 Type conflict when calling a function module. 原来 ...

  9. [Usaco2007 Feb]Cow Party

    题目描述 农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前 ...

  10. bootstrap 后端模板

    Twitter Bootstrap 框架已经广为人知,用于加快网站,应用程序或主题的界面开发,并被公认为是迄今对于 Web 开发的最有实质性帮助的工具之一.在此之前的,各种各样的界面库伴随着高昂的维护 ...