当前位置:网站首页>Codeforces Round #623
Codeforces Round #623
2022-04-22 07:28:00 【INGg__】
A - Dead Pixel
The question
A resolution of a*b On your screen x,y There is a bad point at this point , Ask what is the maximum area that can be displayed
Answer key
The pixel coordinates are from 0 At the beginning , For the sake of good calculation, we directly from 1 Start counting
Just output the largest in the four areas around this point
Code
ll a, b, x, y;
void solve(){
cin >> a >> b >> x >> y;
x++, y++;
cout << max({
(y - 1) * a, (x - 1) * b, (a - x) * b, (b - y) * a}) << endl;
}
B - Homecoming
The question
One can make a bus or a tram to get to the stop sign quickly
The rule of riding is if you arrive j Point must be the current point to j-1 All points must be the same point , The last one is not necessarily the same
existing p money , Ask this person from 1 What station can I walk to
Answer key
We don't know where he'll start taking the bus , But we know he will arrive n This point
Arrive at the same time n The amount of money remaining at this point must also be greater than or equal to 0
So let's reverse simulate , from n set out , See what point you can't take the bus
Code
void solve(){
cin >> a >> b >> p;
cin >> s;
int n = s.size();
s = ' ' + s;
if(p < a && p < b){
cout << n << endl;
re;
}
for (int i = n; i >= 2; i--){
// cout << p << e ndl;
if(p < a && p < b){
cout << i << endl;
re;
}
int j = i - 1;
if(s[i - 1] == 'A'){
while(j >= 1 && p >= a && s[j] == s[i - 1]){
j--;
}
p -= a;
i = j + 2;
}
else{
while(j >= 1 && p >= b && s[j] == s[i - 1]){
j--;
}
p -= b;
i = j + 2;
}
}
cout << 1 << endl;
}
C - Restoring Permutation
The question
Here's a number n,n It's an array b The number of elements ,b[i]=min(a[i*2-1],a[i*2]), Recover the legal array a, And let a The dictionary order of the string of elements should be as small as possible ,a The smallest element is 1, Maximum time 2*n, If a Can't recover , Output -1
Answer key
Greedy placement , If you can't play any more, you can directly output -1
Code
void solve(){
cin >> n;
vector<int> a, b(n);
map<int, int> st;
for (int i = 0; i < n; i++){
cin >> b[i];
st[b[i]]++;
}
if(count(all(b), 2 * n) != 0){
// Can don't
cout << -1 << endl;
return;
}
for(auto i : b){
a.pb(i);
int j = i + 1;
while(j < 2 * n && st[j])
j++;
if(j > 2 * n || st[j]){
// cout << 2 << endl;
cout << -1 << endl;
return;
}
a.pb(j);
st[j] = 1;
}
for(auto i : a)
cout << i << ' ';
cout << endl;
}
D - Recommendations
The question
The minimum cost of making the number of each book different
Answer key
Reference resources :https://www.bilibili.com/video/BV127411u78f?p=4
Let's make all the books by the number of repetitions , Add one to all except the largest one
Until there is no biggest
Let's set the total cost of the current repeat quantity as sum, The biggest cost is mx, So the increased cost except the biggest one is sum-mx
Code
int n;
PII a[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);
int ans = 0;
int now = 0; // The current number
int summ = 0;
priority_queue<int> q;
for (int i = 1; i <= n; i++){
while(q.size() && now < a[i].x){
// now Less than a[i].x It means that we can't put a[i] Put it in
int mx = q.top();
ans += summ - mx; // contribution
summ -= mx; // The total has been added up to one , new sum There is a change
q.pop();
now++;
}
q.push(a[i].y);
now = a[i].x;
summ += a[i].y;
}
while(q.size()){
// Add all the last
int mx = q.top();
ans += summ - mx;
summ -= mx;
q.pop();
}
cout << ans;
}
版权声明
本文为[INGg__]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220613560325.html
边栏推荐
- blog同步更新通知
- 15 · 全排列
- Blog synchronization update notification
- [DRC 23-20] Rule violation (REQP-1712) Input clock driver - Unsupported PLLE2_ ADV connectivity.
- SQL Server quick start
- Codeforces Round #610 (Div. 2)
- Written examination for summer internship of meituan spring recruitment -- 20220312
- 最强操作符学习之路(C语言详解)
- Singleton pool, singleton bean, singleton mode
- 系统日志收集系列
猜你喜欢

Host cannot Ping virtual machine in bridging mode

顺序表 增删查(找)

Win10 modify command line default font

内部类使用说明(静态、实例、局部)

最小圆覆盖(计算几何基础)

Leetcode - 5 - (repeated substring < KMP >, longest palindrome substring, transpose matrix, binary tree (left and right) view)

A.Binary Seating (概率) (2021年度训练联盟热身训练赛第五场)

重写与重载的定义与区别

队列(详解)——手撕队列习题

This关键字详细概述
随机推荐
LaTex中插入图片报错Unknown graphics extension: .1.jpg. }
Leetcode - 5 - (repeated substring < KMP >, longest palindrome substring, transpose matrix, binary tree (left and right) view)
189. 轮转数组
队列(详解)——手撕队列习题
Error: [HSI 55-1545], unable to generate fsbl normally, unable to read in MSS file, failed to close system mss
Vivado generates and invokes EDF netlist files
Educational Codeforces Round 125 (Rated for Div. 2)
Codeforces Round #779 (Div. 2)
Codeforces Round #776 (Div. 3)
小题记录——
系统日志收集系列
下面这段SQL能否用索引优化查询性能
Codeforces Round #588 (Div. 2) C D
C.Ducky Debugging(简单判断/签到)(2021年度训练联盟热身训练赛第五场 )
L2-002 链表去重(测试点1的坑)
323 · 字符串游戏
指针 结构体 const 小结
1005 Monopoly 同余求解(2021中国大学生程序设计竞赛CCPC-网络选拔赛重赛)
Yapi的安装与配置(转载)
[solution] Luogu p6186 [noi online 1 improvement group] bubble sorting: [bubble sorting] and [reverse order pair] problems