当前位置:网站首页>【补题日记】[2022牛客暑期多校2]H-Take the Elevator
【补题日记】[2022牛客暑期多校2]H-Take the Elevator
2022-07-28 11:08:00 【cls1277】
Pro
https://ac.nowcoder.com/acm/contest/33187/H
Sol
贪心,一种比较好的理解方法是重量。
因为上升和下降就是逆过程,所以只讲上升的思路,下降同理。在上升时,输入的第一个数字x一定小于第二个数字y,我们可以将人假设重量为1,而电梯的最大重量就是m。
很容易想到先考虑高度最高的人最优,因此按照高度降序来做,那么在上升的时候我们从上到下枚举的时候,优先看到的是y,而如果此时想表示接下来的区间内有一个人,则应该在y处+1,同理,在x处该人已经下去,则-1.
当处理出每个端点人的重量变化后,从上到下枚举每一个人,如果重量超过m,则不得不开一个新的电梯运行,同时记录新开的电梯最高的层数,最后上下电梯取max为电梯运行次数,同样的趟数的上升和下降的最高层数(维护的值)取max,再-1乘2就是答案。
关于排序的问题:肯定是越高越往前放,那如果高度相等呢?优先放-1。理解起来也很容易,我们这个做法就是将人数变成了重量,所以重量越小才会有更多的机会给其他人,而重量只有-1和1,因此在高度相等时,将重量小的放在前。
Code
//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'
const LL maxn = 2e5+5;
LL n, m, k, w, c1, c2;
LL ans1[maxn], ans2[maxn];
struct Node {
LL ops, weight;
};
vector<Node> a, b;
bool operator < (const Node &x, const Node &y) {
if(x.ops!=y.ops) return x.ops>y.ops;
return x.weight<y.weight;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("data.txt","r",stdin);
#endif
cin>>n>>m>>k;
Fo(i,1,n) {
LL x, y; cin>>x>>y;
if(x<y) {
a.push_back({
x, -1});
a.push_back({
y, 1});
} else {
b.push_back({
x, 1});
b.push_back({
y, -1});
}
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for(auto it:a) {
w += it.weight;
if(w > m*c1) ans1[++c1] = it.ops;
}
w = 0;
for(auto it:b) {
w += it.weight;
if(w > m*c2) ans2[++c2] = it.ops;
}
LL c = max(c1, c2), ans = 0;
Fo(i,1,c) {
ans += (max(ans1[i], ans2[i])-1)*2;
}
cout<<ans;
return 0;
}
边栏推荐
- 小水滴2.0网站导航网模板
- STM32 drives st7701s chip (V ⅰ V0 mobile phone screen change price)
- [half understood] zero value copy
- ZBrush 2022 software installation package download and installation tutorial
- 哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
- B2 sub theme / blog b2child sub theme / open source code
- 【补题日记】[2022杭电暑期多校2]K-DOS Card
- Design and implementation of SSM personal blog system
- Server online speed measurement system source code
- Software testing and quality learning notes 1 --- black box testing
猜你喜欢

「学习笔记」树状数组

「以云为核,无感极速」第五代验证码重磅来袭

Install SSL Certificate in Litespeed web server

服务器在线测速系统源码
![完整版H5社交聊天平台源码[完整数据库+完整文档教程]](/img/3f/03239c1b4d6906766348d545a4f234.png)
完整版H5社交聊天平台源码[完整数据库+完整文档教程]

An example of the mandatory measures of Microsoft edge browser tracking prevention

【一知半解】零值拷贝

擦黑板特效表白H5源码+非常浪漫/附BGM

天狼星网络验证源码/官方正版/内附搭建教程

Dialogue with Zhuang biaowei: the first lesson of open source
随机推荐
Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held
R language uses dplyr package group_ By function and summarize function calculate the mean value of all covariates involved in the analysis based on grouped variables (difference in means of covariate
Quickly deploy mqtt clusters on AWS using terraform
1331. 数组序号转换
天狼星网络验证源码/官方正版/内附搭建教程
Outlook suddenly becomes very slow and too laggy. How to solve it
Function of interface test
B2 sub theme / blog b2child sub theme / open source code
R language uses LM function to build regression model with interactive items, and uses: sign (colon) to represent the interaction of variables (colon is pure multiplication, excluding the constituent
WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
WPF dependent attribute (WPF dependent attribute)
擦黑板特效表白H5源码+非常浪漫/附BGM
Xiaoshuidi 2.0 website navigation network template
Thinkphp5 behavior hook return result (data) example
Minikube initial experience environment construction
R language uses LM function to build regression model, uses the augmented function of bloom package to store the model results in dataframe, and uses ggplot2 to visualize the regression residual diagr
[极客大挑战 2019]BabySQL-1|SQL注入
Refresh your understanding of redis cluster
一种比读写锁更快的锁,还不赶紧认识一下