当前位置:网站首页>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;
}
边栏推荐
- gorm联表查询-实战
- 2022 The Third J Question Journey
- More than 2022 cattle school training topic Link with the second L Level Editor I
- Mysql_14 存储引擎
- 找不到DiscoveryClient类型的Bean
- canvas Gaussian blur effect
- 阅读笔记:如何理解DevOps?
- 2022牛客多校第三场 A Ancestor
- Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?
- Software test interview questions: BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
猜你喜欢
![[Cloud Native--Kubernetes] Pod Controller](/img/e1/1a8cc82223f9a9be79ebbf1211e9a4.png)
[Cloud Native--Kubernetes] Pod Controller

node uses redis

Cloud native - Kubernetes 】 【 scheduling constraints

could not build server_names_hash, you should increase server_names_hash_bucket_size: 32

Essential knowledge for entry-level 3D game modelers

论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》

导入JankStats检测卡帧库遇到问题记录

Mysql_14 存储引擎

电子行业MES管理系统的主要功能与用途

机器学习(公式推导与代码实现)--sklearn机器学习库
随机推荐
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
克服项目管理中恐惧心理
SV 类的虚方法 多态
进程间通信和线程间通信
D - I Hate Non-integer Number (count of selected number dp
Software Testing Interview Questions: About Automated Testing Tools?
tiup status
简单的顺序结构程序(C语言)
leetcode:269. 火星词典
Flask框架 根据源码分析可扩展点
《MySQL入门很轻松》第2章:MySQL管理工具介绍
redis可视化管理软件Redis Desktop Manager2022
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
tiup status
tiup uninstall
数据类型-整型(C语言)
Huggingface入门篇 II (QA)
ansible学习笔记分享-含剧本示例
Mysql_13 事务
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32