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 ...
随机推荐
- 校园社团活动管理系统(适合小白)基础javaweb前端项目实战【包含增删改查,mysql】一
校园社团活动管理系统(20分) 1.项目需求: 校园社团作为高校课外活动的重要组成部分,发展十分迅速,也受到越来越多学生的欢迎,社团规模.数量等都在日益增长,社团活动也更为多样和丰富.然而,大多数高校 ...
- extern关键字的用法
extern关键字的理解 extern是C/C++语言中的一个关键字,用于声明一个变量或函数具有外部链接性(external linkage),即这些变量或函数可以被其他文件访问. 在C/C++中,如 ...
- 神经网络入门篇:详解核对矩阵的维数(Getting your matrix dimensions right)
核对矩阵的维数 当实现深度神经网络的时候,其中一个常用的检查代码是否有错的方法就是拿出一张纸过一遍算法中矩阵的维数. \(w\)的维度是(下一层的维数,前一层的维数),即\({{w}^{[l]}}\) ...
- Centos、openEuler OS更改源地址
1.配置openEuler软件源仓库 注:以openEuler OS为例,Centos OS相似 vim /etc/yum.repos.d/openEuler.repo 2.常用的源地址 #华为源: ...
- java的反应式流
Java的反应式流是一种新的编程模型,它在异步和事件驱动的环境下工作.反应式流的目的是为了解决传统的单线程或者多线程编程模型在高并发和大流量情况下的性能瓶颈. 反应式流的核心是Observable和O ...
- 将多个txt文件中的内容写在一个txt中的方法
import os filename='./train_data/img_' for i in range(1,19736): newfile=filename+str(i)+'.txt' if os ...
- 使用MapStruct出现了No property named "productId" exists in source parameter(s). Type "Product" has no properties.
pom.xml <properties> <maven.compiler.source>17</maven.compiler.source> <maven.c ...
- #11独立开发周总结|核心OKR1000元/月已达标
核心OKR:1000元/月达成情况 算上微信上收费了200多元,核心OKR已达标 12.25-12.29本周完成事项 产品方面 本周产品上主要是在进行重构的测试,顺利上线,线上问题也比较少 运营方面 ...
- 简单介绍JDK、JRE、JVM三者区别
简单介绍JDK vs JRE vs JVM三者区别 文编|JavaBuild 哈喽,大家好呀!我是JavaBuild,以后可以喊我鸟哥,嘿嘿!俺滴座右铭是不在沉默中爆发,就在沉默中灭亡,一起加油学习, ...
- Spring Boot入坑-1-入坑准备&Spring简介
[写在前面] 长期做基于Spring Boot的企业应用,计划将与应用相关的技术点,通过简介.步骤.示例的方式,记录并分享出来,用于作为Spring Boot入门的记录与教程 计划的内容有: Spri ...