当前位置:网站首页>2022 Nioke Multi-School Training Session H Question H Take the Elevator
2022 Nioke Multi-School Training Session H Question H Take the Elevator
2022-08-05 00:23:00 【Rain Sure】
题目链接
题目大意
大概意思就是,Gave us a broken elevator,And some information about the passengers who need to take the elevator and the maximum capacity of the elevatorm.Ask us the minimum time required for the elevator to transport all passengers to the command floor.
题解
很明显的贪心题,但是不太好想,Here is an idea.
We consider ascending passengers and descending passengers separately,Because if the elevator starts to descend,Then it cannot go up any further;So we let the elevator go as high as possible every time you lie down,Then the time it takes for each trip is to take the largest one for ascending and descending;
主要实现方法:
Suppose the current moving range is [ l , r ] [l, r] [l,r],假设 l < r l < r l<r,Then the current is the upward direction,我们在 l l l处-1,在 r r r处+1,That is, into the elevator-1,出电梯+1; Then consider the highest point,The current highest point is the highest position the elevator will reach;
In the same way, consider the direction of descent:假设当前区间为 [ l , r ] [l, r] [l,r], l > r l > r l>r, l l l处-1, r r r处+1.Then sort all the points,Consider the highest position first,大概思路就是这样,细节看代码吧.
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
typedef struct node
{
int pos, type;
bool operator < (const struct node &w) const {
if(pos != w.pos) return pos > w.pos;
return type < w.type;
}
}Node;
vector<Node> up, down; // Rising and falling passengers are stored separately
int n, m, k;
signed main()
{
cin >> n >> m >> k;
for(int i = 0; i < n; i ++){
int a, b; cin >> a >> b;
if(a < b) {
up.push_back({
a, -1});
up.push_back({
b, 1});
}else{
down.push_back({
a, 1});
down.push_back({
b, -1});
}
}
vector<int> t1, t2; // The maximum heights for ascent and descent are stored separately for each trip
sort(up.begin(), up.end());
sort(down.begin(), down.end());
int temp = 0;
for(auto item : up) {
temp += item.type;
if(temp > t1.size() * m) t1.push_back(item.pos);
}
temp = 0;
for(auto item : down) {
temp += item.type;
if(temp > t2.size() * m) t2.push_back(item.pos);
}
int res = 0;
for(int i = 0; i < t1.size() || i < t2.size(); i ++){
temp = 0;
if(i < t1.size()) temp = max(temp, t1[i]);
if(i < t2.size()) temp = max(temp, t2[i]);
res += (temp - 1) * 2;
}
cout << res << endl;
}
边栏推荐
- lua 如何 实现一个unity协程的工具
- Software testing interview questions: test life cycle, the test process is divided into several stages, and the meaning of each stage and the method used?
- Mysql_13 事务
- 软件测试面试题:做好测试计划的关键是什么?
- 论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
- 【LeetCode】图解 904. 水果成篮
- 标识符、关键字、常量 和变量(C语言)
- MAUI Blazor 权限经验分享 (定位,使用相机)
- [230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
- what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
猜你喜欢

刘润直播预告 | 顶级高手,如何创造财富

元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?

What is next-generation modeling (with learning materials)
![[LeetCode] Summary of Matrix Simulation Related Topics](/img/80/bd71ca5211cce5805909015a642893.jpg)
[LeetCode] Summary of Matrix Simulation Related Topics

国内网站用香港服务器会被封吗?

The master teaches you the 3D real-time character production process, the game modeling process sharing

Senior game modelers tell newbies, what are the necessary software for game scene modelers?

图解 Canvas 入门

TinyMCE禁用转义

Modelers experience sharing: model study method
随机推荐
2022牛客多校训练第二场 H题 Take the Elevator
软件开发工具的技术要素
【Unity编译器扩展之进度条】
Zombie and orphan processes
僵尸进程和孤儿进程
2022杭电多校第三场 L题 Two Permutations
机器学习(公式推导与代码实现)--sklearn机器学习库
Redis visual management software Redis Desktop Manager2022
软件测试面试题:LoadRunner 分为哪三个模块?
gorm的Raw与scan
2022杭电多校 第三场 B题 Boss Rush
2022杭电多校第一场 1004 Ball
ARC129E Yet Another Minimization 题解 【网络流笔记】
Mysql_13 事务
leetcode: 269. The Martian Dictionary
canvas Gaussian blur effect
2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
tiup status
进程间通信和线程间通信
Flask框架 根据源码分析可扩展点