当前位置:网站首页>"Weilai Cup" 2022 Niuke summer multi school training camp 2 h.[take the elevator] maintenance section
"Weilai Cup" 2022 Niuke summer multi school training camp 2 h.[take the elevator] maintenance section
2022-07-26 01:30:00 【HeartFireY】
H.Take the Elevator simulation
Topic analysis
Given k k k Floor building , Now there is an elevator from 1 1 1 Building departure , At most m m m people , There is something wrong with the elevator , When running down, you must reach 1 1 1 The building can change its direction . Yes n n n I hope from a i a_i ai The floor arrives b i b_i bi floor , Ask how many times the elevator needs to run at least .
set up a n s u p [ i ] ansup[i] ansup[i] It means the first i i i The highest number of floors reached by the wheel , a n s d o w n [ i ] ansdown[i] ansdown[i] It means the first i i i The highest level of departure , Then the final answer is to enumerate rounds i i i, a n s + = max ( a n s u p [ i ] , a n s d o w n [ i ] ) ∗ 2 − 2 ans += \max(ansup[i], ansdown[i]) * 2 - 2 ans+=max(ansup[i],ansdown[i])∗2−2, Get the final answer .
Then it can be divided into two processes , Save all endpoints separately ( Marked ), The number of rounds allocated to each passenger can pass ⌈ m + c n t m ⌉ \lceil \frac{m + cnt}{m}\rceil ⌈mm+cnt⌉ obtain .
Code
#include <bits/stdc++.h>
#pragma gcc optimize(2)
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 1e9 + 7;
struct node{
int s, t; }up[N], down[N];
int ansup[N], ansdown[N];
inline void solve(){
int n = 0, m = 0, k = 0; cin >> n >> m >> k;
int upcnt = 0, downcnt = 0;
for(int i = 1; i <= n; i++){
int a, b; cin >> a >> b;
if(a < b) up[++upcnt] = node{
.s = a, .t = 1}, up[++upcnt] = node{
.s = b, .t = -1};
else down[++downcnt] = node{
.s = a, .t = -1}, down[++downcnt] = node{
.s = b, .t = 1};
}
int upans = 0, downans = 0;
sort(up + 1, up + 1 + upcnt, [](const node &x, const node &y){
return x.s < y.s || x.s == y.s && x.t < y.t; });
sort(down + 1, down + 1 + downcnt, [](const node &x, const node &y){
return x.s < y.s || x.s == y.s && x.t < y.t; });
int now = 0;
for(int i = 1; i <= upcnt; i++){
if(up[i].t == -1)
ansup[(now + m - 1) / m] = up[i].s;
now += up[i].t;
}
assert(now == 0);
for(int i = 1; i <= downcnt; i++){
if(down[i].t == -1)
ansdown[(now + m - 1) / m] = down[i].s;
now += down[i].t;
}
int ans = 0;
for(int i = 1; i <= 200000; i++)
ans += 2 * max({
1ll, ansup[i], ansdown[i]}) - 2;
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- 推荐⼀款超好⽤的UI⾃动化⼯具: UiAutomator2!
- Lua basic grammar
- [data mining] differences, advantages and disadvantages between generative model and discriminant model
- Test questions and answers of the latest Beijing Construction eight (materialman) mock examination in 2022
- [go] how to control the maximum number of concurrent processes
- Format JS code and debug JS code
- Kubernetes pod start process
- Is it safe for Huatai Securities to open an account online? How to handle it?
- Advanced C language (I) dynamic memory allocation
- 3059. Sculpture (jzoj)
猜你喜欢

What if win11 cannot open its own anti-virus software? Win11's built-in anti-virus function cannot be turned on
![[data mining] differences, advantages and disadvantages between generative model and discriminant model](/img/a4/3dba2ba9fa0fe3062f17aea2bfae47.png)
[data mining] differences, advantages and disadvantages between generative model and discriminant model

格式化JS代码,调试JS代码

聚势|海泰方圆亮相第五届数字中国建设峰会

Lua basic grammar
![[combinational logic circuit] - encoder](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)
[combinational logic circuit] - encoder

第二届中国Rust开发者大会来啦,完整议程大曝光!

两阶段提交和三阶段提交

Zero copy of network file transfer

Modify CSV
随机推荐
# 浏览器开发使用技巧
Spark-SQL中根据年月日显示周几用date_format(date,‘u‘)
链表相关面试题
Causes of signal degradation in optical fiber communication
服务器可用资源查询脚本
PTGui Pro12垂直线纠正
Record a failure caused by a custom redis distributed lock
Easyrecovery15 data recovery software with high recovery rate and high download volume
NiO simple example
"Yuanqi Cola" is not the end point, "China Cola" is
Leetcode537. 复数乘法(可以,已解决)
大咖观点+500强案例,软件团队应该这样提升研发效能
How to obtain the cash flow data of advertising services to help analyze the advertising effect?
4QAM、16QAM 调制与解调仿真电路,观察并分析QAM星座图和误码率曲线【matlab代码】
网络性能评估工具 ping/mtr
Codisvsrediscluster: which cluster scheme should I choose?
[secsha concept] original reverse supplement
Format JS code and debug JS code
Codeforces Round #810 (Div. 2)A~C
Cross linguistic transfer of correlations between parts of speech and Gazette Features Reading Notes