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 ...
随机推荐
- 纯css步骤条编写
.steps { position: relative; margin-bottom: 30px; counter-reset: step; /*创建步骤数字计数器*/ } /*步骤描述*/ .ste ...
- Modbus转PROFINET网关助力电子天平与西门子PLC无缝对接
背景: 在制药.食品科学和其他行业中,电子天平被广泛用于质量控制和分析实验.它们可以用于检测样品的净重.含量和浓度,并用于监测产品的制造过程. 常州某反应器公司实验室近期采购一批电子天平,现需要把电子 ...
- macOS上有哪些值得推荐的常用软件
macOS 作为一款流行的操作系统,拥有丰富的第三方软件生态系统,涵盖了各种领域的应用程序.以下将介绍一些在 macOS 上备受推崇的常用软件,并对它们进行详细的介绍和说明. 1. 生产力工具 a. ...
- CompletableFuture入门
CompletableFuture入门 1.Future vs CompletableFuture 1.1 准备工作 先定义一个工具类 import java.nio.file.Files; impo ...
- AVL树和红黑树的Python代码实现
AVL树 AVL树是一种自平衡二叉搜索树.在这种树中,任何节点的两个子树的高度差被严格控制在1以内.这确保了树的平衡,从而保证了搜索.插入和删除操作的高效性.AVL树是由Georgy Adelson- ...
- django-filter的详细使用
有时候前端需要各种各样的过滤查询,如果自己写多少有点麻烦和冗余.使用django-filter就可以很好的解决这个问题. django-filter可以用在django上, 也与配合drf一起使用. ...
- ElasticSearch之Clear cache API
本方法用于清理缓存. 命令样例如下: curl -X POST "https://localhost:9200/testindex_001/_cache/clear?pretty" ...
- MySQL的事务(看看也许有帮助呢)
MySQL的事务 一.事务的概念 在MySQL中,只有InnoDB存储引擎才支持事务. 事务的处理用来维护数据库数据的完整性,保证同一个事务里的一批SQL语句,要么全部执行,要么全部不执行. 事务用来 ...
- 9 个让你的 Python 代码更快的小技巧
哈喽大家好,我是咸鱼 我们经常听到 "Python 太慢了","Python 性能不行"这样的观点.但是,只要掌握一些编程技巧,就能大幅提升 Python 的运 ...
- react+echarts出现“There is a chart instance already initialized on the dom.”
写了一个关于echatrs组件,报错dom重复 配置信息从props拿 let chart; useEffect(() => { if (chart) { updateChartView(); ...