当前位置:网站首页>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;
}
边栏推荐
- [LeetCode] Summary of Matrix Simulation Related Topics
- 翁恺C语言程序设计网课笔记合集
- Will domestic websites use Hong Kong servers be blocked?
- canvas 高斯模糊效果
- leetcode:267. 回文排列 II
- Cloud native - Kubernetes 】 【 scheduling constraints
- node使用redis
- MAUI Blazor 权限经验分享 (定位,使用相机)
- 克服项目管理中恐惧心理
- ARC129E Yet Another Minimization 题解 【网络流笔记】
猜你喜欢
随机推荐
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
What is next-generation modeling (with learning materials)
测试经理要不要做测试执行?
Huggingface入门篇 II (QA)
软件测试面试题:设计测试用例时应该考虑哪些方面,即不同的测试用例针对那些方面进行测试?
[LeetCode] Summary of Matrix Simulation Related Topics
tiup uninstall
#yyds dry goods inventory #Switching equipment serious packet loss troubleshooting
E - Distance Sequence (前缀和优化dp
2022牛客多校训练第二场 J题 Link with Arithmetic Progression
【LeetCode】双指针题解汇总
软件测试面试题:软件都有多少种分类?
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
性能测试如何准备测试数据
克服项目管理中恐惧心理
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
2 用D435i运行VINS-fusion
uinty lua 关于异步函数的终极思想
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
机器学习(公式推导与代码实现)--sklearn机器学习库









