当前位置:网站首页>"Weilai Cup" 2022 Niuke summer multi school training camp 2H
"Weilai Cup" 2022 Niuke summer multi school training camp 2H
2022-07-29 04:05:00 【Snow_ raw】
" Weilai cup "2022 Niuke summer multi school training camp 2 H
The question : Yes n n n One should take the elevator , from a a a Sit on the floor until b b b layer , The full load of the elevator is m m m people , The total floor is k k k layer , The elevator can rise from floor to floor , Any layer can choose to descend . But the decline must fall to 1 1 1 The layer can only rise again . The energy consumed by the elevator moving between floors is 1 1 1 , Ask us how much it costs at least to make everyone successfully reach the destination .
Ideas : There are prefixes and algorithmic knowledge prerequisites , Let's first look at the rising personnel , We calculate how many times each floor is passed by the elevator at least , Differential can be used , Finally, merge . For example, if from 3 3 3 Floor to floor 6 6 6 floor , We go through O ( 1 ) O(1) O(1) stay 4 4 4 Floor location + 1 +1 +1, 7 7 7 Location of building − 1 -1 −1 that will do . representative 4 − 6 4-6 4−6 The number of times building passed + 1 +1 +1, 3 3 3 There is no need to add floors because 3 3 3 The first floor does not need to consume elevator energy . At last, the prefix and operation count the minimum number of people passing on all floors , And divide each layer by m m m Round up , Express Under full load , The elevator Still need How many times have you passed the current floor . And one thing is obvious , If the upper floor passes at least more than the lower floor , Then the lower floor also needs the elevator to pass the same number of times as the upper floor . for example 7 7 7 Layer passes at least 3 3 3 Time , that 7 7 7 The number of elevators passing on floors and below cannot be less than 3 3 3 Time . Finally, you can get the minimum value of the energy spent by the elevator on the rising floor . Next, we will discuss the descending floor , You will find that a large part of the descending floor will repeat with the ascending floor , The process of choosing to descend and then rise again at each rising floor can also make many descending personnel reach the target floor , So we need to be on the same floor Rise and fall Select a maximum number of times .
Code :
/* * @author: Snow * @Description: Algorithm Contest * @LastEditTime: 2022-07-28 19:40:33 */
#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize(3)
#define re register int
typedef pair<int,int>PII;
#define pb push_back
#define debug(a) cout<<a<<' ';
#define fer(i,a,b) for(re i=a;i<=b;i++)
#define der(i,a,b) for(re i=a;i>=b;i--)
int n,m,k;
const int N = 2e5+10;
int suf[N];
int a[N];
int b[N];
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m>>k;
vector<int>v;
for(int i=1;i<=n;i++){
cin>>a[i];
cin>>b[i];
v.pb(a[i]);
v.pb(b[i]);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int sum=v.size();
vector<int>up,down;
for(int i=1;i<=n;i++){
int l=lower_bound(v.begin(),v.end(),a[i])-v.begin();
int r=lower_bound(v.begin(),v.end(),b[i])-v.begin();
if(l<r){
up[l+1]++;
up[r+1]--;
}
else{
down[r+1]++;
down[l+1]--;
}
}
for(int i=1;i<=sum;i++){
up[i]+=up[i-1];
down[i]+=down[i-1];
int ti1=(up[i]+m-1)/m;
int ti2=(down[i]+m-1)/m;
suf[max(ti1,ti2)]=max(suf[max(ti1,ti2)],v[i]-1);
}
for(int i=n-1;i>=1;i--)suf[i]=max(suf[i],suf[i+1]);
int ans=0;
for(int i=n;i>=1;i--)ans+=suf[i];
cout<<ans<<endl;
return 0;
}
边栏推荐
- 华为天才少年稚晖君做了一把模块化机械键盘,引起极客圈地震,网友:这才是真正的客制化...
- 第一个ALV程序2
- Value transmission and address transmission of C language, pointer of pointer
- 数据挖掘——关联分析例题代码实现(下)
- 内连接和左连接简单案例
- 【深度学习CPU(番外篇)——虚拟内存】
- 数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
- Typescript from introduction to proficiency (XXIV) using import syntax
- Array as function parameter -- pointer constant / constant pointer
- MySQL Part 4 (end)
猜你喜欢

Typescript from getting started to mastering (XX) function generics

基于STM32和阿里云的环境检测系统设计

STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案

华为天才少年稚晖君做了一把模块化机械键盘,引起极客圈地震,网友:这才是真正的客制化...
![[deep learning CPU (part outside) - virtual memory]](/img/f7/4c72d583456f6f68c52424602ff5d9.png)
[deep learning CPU (part outside) - virtual memory]

初识C语言(3)

数据挖掘——关联分析例题代码实现(下)

Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理

Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes

Nacos registry
随机推荐
当我从数据库获取到了winfrom特定的控件ID之后我需要通过这个ID找到对应的控件,并对控件的TEXT文本进行赋值这该怎么做
First knowledge of C language (3)
Typescript from getting started to mastering (XXIII) namespace namespace (Part 2)
伏英娜:元宇宙就是新一代互联网!
C language - character array - string array - '\0' -sizeof-strlen() -printf()
Since 2019, you must have stopped using this marketing strategy
Configmap configuration and secret encryption
请问为什么我进行mysql数据update时,kafka中采集到的是先删除原纪录(op d)再新增新
关于ALV格式控制部分的写法
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
Typescript from entry to mastery (XVIII) joint type and type protection
How to write SQL statements about field conversion
优炫数据库有办法查到主集群每天传给备集群的日志量吗?
Some problems about pointers
Communication between parent-child components and parent-child components provide and inject
数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
Array as function parameter -- pointer constant / constant pointer
Ssl== certificate related concepts
Const read only variable constant