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. 报错:bs4.FeatureNotFound: Couldn't find a tree builder with the features you requ

    安装 pip3 install lxml 即可

  2. nordic的nrf52系列32M速率的SPI-SPIM3

    简介:在nordic的nrf52系列中的nrf52833和nrf52840的SPIM3都是支持最大32M的spi速率,其余的只有8M,当在需要刷屏,或者一些需要高速32M-SPI时,这是一个很好的使用 ...

  3. [ARC145B] AB Game

    The game is played by Alice and Bob. Initially, there are $n$ stones. The players alternate turns, m ...

  4. Spring整合Quartz简单入门

    创建一个Web项目 导入相关jar包 <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  5. Oracle参数文件spfile

    spfile:server parameter file. spfile只能通过OEM(oracle enterprise manager)软件或者alter system命令进行修改. spfile ...

  6. Netty源码学习9——从Timer到ScheduledThreadPoolExecutor到HashedWheelTimer

    系列文章目录和关于我 一丶前言 之前在学习netty源码的时候,经常看netty hash时间轮(HashedWheelTimer)的出现,时间轮作为一种定时调度机制,在jdk中还存在Timer和Sc ...

  7. Javascript Ajax总结——GET请求和POST请求

    1.GET请求GET最常用于向服务器查询信息.可在URL末尾添加查询字符串参数.XHR中,传入open()方法的URL末尾的查询字符串必须经过正确的编码,使用encodeURIComponent()编 ...

  8. CentOS7,配置rsyslog客户端地址

    在CentOS 7系统,将所有日志转发到 192.168.168.168 日志服务器,你可以按照以下步骤进行配置: 确保rsyslog已经被安装 rpm -qa|grep rsyslog 1.打开 r ...

  9. Tpon 1.0 一键查询网站存在过的路径

    Tpon 1.0 寻找网站存在过的路径 该工具能够让你发现意料之外的路径 工具描述 编写该工具旨在寻找网站存在过的网站路径,这个地址可能是机器爬下来的也可能是某些人访问过的,在表面你可能看不到它的入口 ...

  10. GitHub OAuth2的授权指南

    一.OAuth2简介 OAuth 2.0(开放授权 2.0)是一种用于授权的开放标准,旨在允许用户在不提供他们的用户名和密码的情况下,授权第三方应用访问其在另一网站上的信息.它是在网络服务之间安全地共 ...