1443A. Kids Seating

题意: 给你一个整数n,现在你需要从编号 \(1\) ~ $4 ⋅ n \(中选出\)n\(个编号使得这些编号之间\)g c d ≠ 1$ ,不能整除。

看了半天,发现只要满足 \(起始点在 2 · n + 2,然后依次增加2\) 即可

void solve() {
cin >> n;
for (int i = 2 * n + 2; i <= 4 * n; i += 2) cout << i << " ";
cout << endl;
}
for _ in range(int(input())):
n = int(input())
print(*[2*i+2*n+2 for i in range(n)])

1443B. Saving the City

题意:

现在城市中有一些炸弹,但我们的拆弹专家知道如何引爆炸弹而不影响建筑(引爆时会使整个连续区间的炸弹都爆炸)。引爆一次炸弹需要 \(a\) 花费,而添加一个炸弹需要 \(b\) 花费。问怎么做才能使消费最小

思路:

由于任何地雷的激活都会炸毁整个地雷段,因此您可以立即用一系列地雷段替换输入字符串。 现在,我们有两个操作。 我们可以用硬币删除任何分段,或者将两个相邻的分段 \([l1,r1],[l2,r2] (r1 <l2)\)变成 \(b⋅(l2-r1)\)的分段。 即,可以以 \(2⋅a\) 或 \(a +b⋅(l2-r1)\) 的代价删除两个片段。 这意味着您需要在 \(b⋅(l2-r1)≤a\) 时合并两个段。 所以想到取到最小花费只需要遍历所有相邻的路段并检查这种情况。

void solve() {
int a, b; cin >> a >> b;
string s; cin >> s;
int i = 0, len = s.length();
vector<pair<int, int>> v;
while (i < len) {
while (i < len && s[i] == '0') i++;
int j = i;
while (j < len && s[j] == '1') j++;
if (i < len) v.push_back({i, j});
i = j;
}
if (v.size() == 0)
printf("0\n");
else {
int ans = a;
for (int i = 1; i < v.size(); i++) {
ans += min((v[i].first - v[i - 1].second) * b, a);
}
printf("%d\n", ans);
}
}

1443C. The Delivery Dilemma

题意:

你需要点\(n\)个不同的菜,你有两种方式可以选择,一种是点外卖,花费\(a_i\) 时间,一种是自己拿,花费\(b_i\) 时间。你需要在最少的时间中弄完这\(n\) 个菜。

思路:

因为选择点外卖一直是需要人在家的(等价于点外卖一定是最大时间),那么根据贪心思想只需要统计自己拿的时间总和(此时需要自定义排序)

// Author : RioTian
// Time : 20/11/03
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
struct node {
int x, y;
} a[maxn];
bool cmp(node a, node b) { return a.x < b.x; }
ll _, n;
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].x;
for (int i = 1; i <= n; ++i) cin >> a[i].y;
sort(a + 1, a + 1 + n, cmp);
int now = n, sum = 0;
while (now >= 1) {
if (a[now].x > sum + a[now].y) {
sum += a[now].y;
now--;
} else
break;
}
cout << max(a[now].x, sum) << '\n';
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _;
while (_--) solve();
}

1443D. Extreme Subtraction

思路:(来自比赛提示)

问题看起来像是-检查是否有递增和递减的数组,它们在元素上的总和等于给定的数组。

这个问题可以贪婪地解决。 让我们最大化递减数组的每个元素(我们称此数组为a,递增数组为b)。 假设初始数组为v,我们已经解决了长度为\(i-1\)的前缀的问题。 然后,对于元素a [i],必须满足\(a [i]≤a[i-1]\)和\(v [i] -a [i]≥b[i-1]\)。 重写第二个不等式并与第一个不等式组合,我们得到\(a [i]≤min(a [i-1],v [i] -b [i-1])\)。 显然,通过构造最好采用\(a [i] = min(a [i-1],v [i] -b [i-1])\)。

void solve() {
int n;
cin >> n;
vector<int> arr(n), last(n);
int rem = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int l = arr[0], r = 0;
for (int i = 1; i < n; i++) {
if (r > arr[i]) {
cout << "NO\n";
return;
}
if (l + r < arr[i]) {
r = arr[i] - l;
} else {
l = arr[i] - r;
}
}
cout << "YES\n";
}

E、F表示没怎么看懂题,待补状态。。。

Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) 个人题解(A - D)的更多相关文章

  1. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】

    比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...

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

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

  3. 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\). 题解: ...

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

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

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

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

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

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

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

  8. 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( ...

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

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

  10. 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. VisionPro学习笔记(5)——极轴展开工具PolarUnwrapTool

    如果需要了解其他图像处理的文章,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice ...

  2. [USACO2007OPENG] Dining G

    题目描述 Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she w ...

  3. 【matlab混沌理论】1.3.双摆杆基本模型

    双摆杆是混沌理论的典型运动模型之一.涉及重力加速度.摆杆长度和质量. 1.双摆杆的摆角分析 input: % 已知物理参数 L1 = 5;L2 = 3; %两摆杆长度和质量 m1 = 3;m2 = 5 ...

  4. 12 HTTP的实体数据

    目录 数据类型和编码 HTTP协议为什么要关心 body MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型 HTTP 常用数据类型 MIM ...

  5. hdu 5685

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5685 解题思路:前缀积+费马小定理求逆元. AC代码: 1 #include<iostream> ...

  6. selenium之三种等待,强制等待、隐式等待和显式等待

    显式等待 presence_of_element_locatedpresence_of_all_elements_locatedvisibility_of_any_elements_located   ...

  7. SpringCloud Gateway 网关

    SpringCloud Gateway 网关 spring: cloud: gateway: routes: - id: after_route uri: https://example.org pr ...

  8. python在容器内克隆拉取git私有仓库

    前言 目前有个python应用需要在容器镜像内拉取git私有仓库的代码,一开始的想法是用GitPython,折腾一番ssh私钥和known_hosts问题后,发现还是在镜像中封装个git最省事,然后用 ...

  9. 【scikit-learn基础】--『监督学习』之 K-近邻分类

    KNN(K-近邻),全称K-Nearest Neighbors,是一种常用的分类算法.KNN算法的历史可以追溯到1957年,当时Cover和Hart提出了"最近邻分类"的概念.但是 ...

  10. Python——Html(语法、格式、段落、文字处理、路径、超链接、图片、视频)

    HTML(Hyper Text Markup Language超文本标记语言)用特殊的一种标签把需要特殊展示出来的内容圈起来.这就是标记语言语法规则 <标记>被标记的内容</标记&g ...