Codeforces Round #623 (Div. 2) A~D题,D题multiset使用
比赛链接:Here
1315A. Dead Pixel
签到题,
比较四个值
max(max(x, a - 1 - x) * b, a * max(y, b - 1 - y))
1315B. Homecoming
\(A\to B\) 花费 \(a\) 元
\(B\to A\) 花费 \(b\) 元
求要走到点 \(i\),从 \(i\) 上车能在 \(p\) 内到终点。
这个挺多解法的
- 二分答案
- 逆推模拟
- DP
虚拟赛的时候写了DP
const int N = 1e6 + 10;
ll f[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int a, b, p; cin >> a >> b >> p;
string s; cin >> s;
int n = s.size();
if (s[n - 1] == 'A') f[n - 1] = a;
else f[n - 1] = b;
f[n] = 0;
ll pos = n - 1;
for (int i = n - 2; i >= 0; --i) {
if (i == n - 2) f[i] = (s[i] == 'A' ? a : b);
else if (s[i] == s[i + 1]) f[i] = f[i + 1];
else f[i] = f[i + 1] + (s[i] == 'A' ? a : b);
}
for (int i = 0; i < n; ++i)
if (f[i] <= p) {pos = i; break;}
cout << pos + 1 << "\n";
}
}
1315C. Restoring Permutation
题意:
给一组长度为 \(n\) 的 \(b[i]\) , 让你找一组长度为 \(2n\) 的 \(a[i]\) , 满足 \(b[i] = min(a[2*i-1 ] ,a[2*i])\) ,并且字典序最小 。
AtCoder 上做过类似的,直接考虑贪心
const int N = 1e4 + 10;
ll a[N], b[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll n;
cin >> n;
map<ll, ll> mp;
for (int i = 1; i <= n; ++i) {
cin >> b[i], mp[b[i]] = 1;
}
bool f = 1;
for (int i = 1;f and i <= n; ++i) {
a[i * 2 - 1] = b[i];
ll k = b[i];
while (mp[k] == 1) k += 1;
if (k <= 2 * n) {
a[i * 2] = k;
mp[k] = 1;
} else f = 0;
}
if (!f) cout << "-1\n";
else
for (int i = 1; i <= 2 * n; ++i)cout << a[i] << " \n"[i == 2 * n];
}
}
1315D. Recommendations
题意:
你有 \(n\) 本书,每本书的数量为 \(a[i]\) ,你可以花费 \(t[i]\) 让这对应的书加 \(1\) ,求总花费最小并使得 \(a[i]\) 各不相同。
利用容器 multiset
每次把同样数量的书放入一个 multiset
里,然后把最大的书拿出来保留,其他的书花费的时间加到答案里,再把 +1
之后书放进去,再反复操作。
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; ++i) cin >> v[i].first;
for (int i = 0; i < n; ++i) cin >> v[i].second;
multiset<int>ms;
sort(v.begin(), v.end());
int c = 1, i = 0;
ll s = 0, r = 0;
while (1) {
if (ms.size() == 0 && i == n) {
cout << r;
return 0;
}
if (ms.size() == 0) c = v[i].first;
for (; i < n && v[i].first == c; ++i) {
ms.insert(-v[i].second);
s += v[i].second;
}
s += *ms.begin();
ms.erase(ms.begin());
r += s, c++;
}
}
Codeforces Round #623 (Div. 2) A~D题,D题multiset使用的更多相关文章
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #303 (Div. 2) D. Queue 傻逼题
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
随机推荐
- .NET生成微信小程序推广二维码
前言 对于小程序大家可能都非常熟悉了,随着小程序的不断普及越来越多的公司都开始推广使用起来了.今天接到一个需求就是生成小程序码,并且与运营给的推广图片合并在一起做成一张漂亮美观的推广二维码,扫码这种二 ...
- IDEA提示java_ 程序包org.apache.ibatis.session不存在
一.解决方案 1.问题原因: 这是因为配置Java的程序包这块出现了错误,同时可能你还没有设置让IDEA自动加载Jar包,才会报出这种错误的. 2.解决方案: 解决方式如下: File->Set ...
- java-生成二维码/条形码
前言: 需求:生成二维码/条形码 //使用ZXing库 <dependencies> <dependency> <groupId>com.google.zxin ...
- [python][图像切割]给定手写数字图片完成数字切割
import torch import torch.nn as nn from torchvision import transforms from PIL import Image, ImageOp ...
- isAlive
线程存活 当线程执行时显示线程存活 执行完毕为false
- Git恢复删除的文件,一行命令就可以啦~
情况一:删除或者修改了某个文件,但是没有add # 单个 git checkout filename # 多个 git checkout . 情况二:删除或者修改了某个文件,已经add,但是没有com ...
- 寻找市场中的Alpha—WorldQuant的阿尔法设计理念(上)
本文旨在向读者介绍Alpha的相关基本概念,以及寻找和检验Alpha的主要流程和方法.在上篇中我们梳理了 WorldQuant经典读本FindingAlphas的概要以及WebSim的使用,在下篇中我 ...
- Bert-vits2-2.3-Final,Bert-vits2最终版一键整合包(复刻生化危机艾达王)
近日,Bert-vits2发布了最新的版本2.3-final,意为最终版,修复了一些已知的bug,添加基于 WavLM 的 Discriminator(来源于 StyleTTS2),令人意外的是,因情 ...
- 华企盾DSC控制台+系统运维模块连接不上问题
解决方法:把rundll32.exe进程结束之后再点系统运维模块
- 设计模式之设计模式概述-shejimoshigaishu
title: 设计模式之设计模式概述 date: 2022-12-04 00:21:18.469 updated: 2022-12-11 23:03:45.617 url: https://www.y ...