当前位置:网站首页>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;
}
边栏推荐
- 《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
- 软件测试面试题:软件测试类型都有哪些?
- D - I Hate Non-integer Number (count of selected number dp
- Software Testing Interview Questions: About Automated Testing Tools?
- 刘润直播预告 | 顶级高手,如何创造财富
- QSunSync Qiniu cloud file synchronization tool, batch upload
- Getting started with 3D modeling for games, what modeling software can I choose?
- 阅读笔记:如何理解DevOps?
- tiup uninstall
- 软件测试面试题:什么是软件测试?软件测试的目的与原则?
猜你喜欢

怎样进行在不改变主线程执行的时候,进行日志的记录

数据类型-整型(C语言)

倒计时1天!8月2日—4日与你聊聊开源与就业那些事!
![[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots](/img/fa/5bdc81b1ebfc22d31f42da34427f3e.png)
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots

测试经理要不要做测试执行?

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

leetcode经典例题——单词拆分

oracle创建用户以后的权限问题

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

数据类型及输入输出初探(C语言)
随机推荐
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
Three tips for you to successfully get started with 3D modeling
2022牛客多校训练第二场 J题 Link with Arithmetic Progression
leetcode:269. 火星词典
软件测试面试题:软件都有多少种分类?
Modelers experience sharing: model study method
网站最终产品页使用单一入口还是多入口?
Huggingface入门篇 II (QA)
D - I Hate Non-integer Number (选数的计数dp
matlab中rcosdesign函数升余弦滚降成型滤波器
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
软件测试面试题:测试用例通常包括那些内容?
More than 2022 cattle school training topic Link with the second L Level Editor I
【LeetCode】双指针题解汇总
Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?
软件测试面试题:LoadRunner 分为哪三个模块?
[idea] idea configures sql formatting
SV 类的虚方法 多态
tiup telemetry
数据类型及输入输出初探(C语言)