当前位置:网站首页>[diary of supplementary questions] [2022 Niuke summer school 2] h-take the elevator
[diary of supplementary questions] [2022 Niuke summer school 2] h-take the elevator
2022-07-28 11:54:00 【cls1277】
Pro
https://ac.nowcoder.com/acm/contest/33187/H
Sol
greedy , A better way to understand is weight .
Because rising and falling are inverse processes , So just talk about the idea of rising , The same goes for falling . On the rise , The first number entered x It must be less than the second number y, We can assume that people weigh 1, And the maximum weight of the elevator is m.
It's easy to think that it's best to consider the highest person first , So do it in descending order , So when we enumerate from top to bottom on the rise , The priority is y, And if you want to indicate that there is a person in the next interval , Should be in y It's about +1, Empathy , stay x This person has gone down , be -1.
After processing the weight change of each endpoint , Enumerate everyone from top to bottom , If the weight exceeds m, Have to open a new elevator to run , At the same time, record the highest floor of the newly opened elevator , Finally, get on and off the elevator max Is the number of elevator runs , The highest level of the rise and fall of the same number of trips ( Maintenance value ) take max, Again -1 ride 2 That's the answer. .
About sorting : It must be higher and forward , What if the height is equal ? Put first -1. It's easy to understand , Our practice is to turn the number of people into weight , So the smaller the weight, the more opportunities for others , And the weight is only -1 and 1, So when the height is equal , Put the light one in front .
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;
}
边栏推荐
- Specific process of strong cache and negotiation cache
- Three methods of using unity mouse to drive objects
- How async await implements concurrency
- Six papers that must be seen in the field of target detection
- Database advanced learning notes -- object type
- What is the process of switching c read / write files from user mode to kernel mode?
- B2 sub theme / blog b2child sub theme / open source code
- Flash point list of cross platform efficiency software
- Start from scratch blazor server (2) -- consolidate databases
- The fifth generation verification code of "cloud centered, insensitive and extremely fast" is coming heavily
猜你喜欢
![Full version of H5 social chat platform source code [complete database + complete document tutorial]](/img/3f/03239c1b4d6906766348d545a4f234.png)
Full version of H5 social chat platform source code [complete database + complete document tutorial]

108. Introduction to the usage of SAP ui5 image display control Avatar

数字孪生轨道交通:“智慧化”监控疏通城市运行痛点

Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held

14. User web layer services (II)

STL の 概念及其应用

Upgrading of computing power under the coordination of software and hardware, redefining productivity

15、用户web层服务(三)

Consumer installation and configuration

「以云为核,无感极速」第五代验证码重磅来袭
随机推荐
An example of the mandatory measures of Microsoft edge browser tracking prevention
LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
Multithreading and high concurrency (III) -- source code analysis AQS principle
Quickly deploy mqtt clusters on AWS using terraform
[geek challenge 2019] babysql-1 | SQL injection
Reflect 机制获取Class 的属性和方法信息
在生产环境中每天Oracle监控到的无效对象一般怎么去处理?
Leecode8 string conversion integer (ATOI)
OSCache cache monitoring Refresh Tool
What is the process of switching c read / write files from user mode to kernel mode?
Shell (II)
The reflect mechanism obtains the attribute and method information of class
How is the JS code compiled and executed by the browser engine?
Advanced database technology learning notes 1 -- Oracle deployment and pl/sql overview
多线程与高并发(三)—— 源码解析 AQS 原理
boost官网搜索引擎项目详解
Today's sleep quality record 74 points
Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
Are interviews all about memorizing answers?