当前位置:网站首页>Csp2021 T1 corridor bridge distribution
Csp2021 T1 corridor bridge distribution
2022-07-24 13:51:00 【lAWTYl】
Corridor bridge assignment
Portal :CSP2021 T1 Corridor bridge assignment
The main idea of the topic
Now there is n n n A covered bridge , m 1 m_1 m1 Domestic flights and m 2 m_2 m2 International Flights . Each flight includes a time to enter the airport and a time to leave the airport . And domestic flights can only stop at the corridor bridge in the domestic area or the remote parking space , The same goes for International Flights . All planes have priority to stop on the corridor bridge .
Now let's assign all the covered bridges to the international area and the domestic area , The total number of planes that can stop at the corridor bridge is the largest , And output the maximum value .
analysis
We make f [ x ] f[x] f[x] Indicates the domestic district x x x The total number of planes that have stopped on the covered bridges , g [ x ] g[x] g[x] Indicates the international zone x x x The total number of planes that have stopped on the covered bridges . So the answer is obviously :
a n s = max i = 0 n { ∑ x = 1 i f [ x ] + ∑ x = i n − i g [ x ] } ans = \max_{i = 0}^n \{ \sum_{x = 1}^i f[x] + \sum_{x = i}^{n - i}g[x] \} ans=i=0maxn{ x=1∑if[x]+x=i∑n−ig[x]}
So what we need to consider now is how to quickly find f f f and g g g These two arrays . And it's very simple , Each time we arrange the smallest number of covered bridges to stop the arriving planes , In this way, the problem of the limitation of the number of covered bridges can be easily solved . That is to say, it is allocated to No n n n After a corridor bridge n + 1 n + 1 n+1 It is equivalent to directly allocating to remote parking stands , No more processing is needed .
The rest is simulation .
Code
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MAXN 100100
typedef pair<int , int> pii; // The first is the departure time The second is the number of the corridor bridge
inline int read(){
int x = 0; char c = getchar();
while(c < '0' or c > '9') c = getchar();
while('0' <= c and c <= '9'){
x = x * 10 + c - '0'; c = getchar();
}
return x;
}
int n = 0;
int m1 = 0; int m2 = 0;
struct Tplane{
int l, r;
bool operator < (const Tplane &rhs) const {
return l < rhs.l; }
}a[MAXN], b[MAXN];
int ans1[MAXN] = {
0 };
int ans2[MAXN] = {
0 };
void solve(Tplane *p, int m, int *ans){
priority_queue<pii, vector<pii>, greater<pii>> lq;
priority_queue<int, vector<int>, greater<int>> wq;
for(int i = 1; i <= n; i++) wq.push(i);
for(int i = 1; i <= m; i++){
while(!lq.empty() and p[i].l >= lq.top().first)
wq.push(lq.top().second), lq.pop();
if(wq.empty()) continue;
int des = wq.top(); wq.pop();
ans[des]++;
lq.push(make_pair(p[i].r, des));
}
for(int i = 1; i <= n; i++) ans[i] += ans[i - 1];
}
int main(){
n = in; m1 = in; m2 = in; int ans = 0;
for(int i = 1; i <= m1; i++) a[i].l = in, a[i].r = in;
for(int i = 1; i <= m2; i++) b[i].l = in, b[i].r = in;
sort(a + 1, a + m1 + 1); sort(b + 1, b + m2 + 1);
solve(a, m1, ans1); solve(b, m2, ans2);
for(int i = 0; i <= n; i++) ans = max(ans, ans1[i] + ans2[n - i]);
cout << ans << '\n';
return 0;
}
边栏推荐
- Wechat applet todo case
- Group knowledge map: distributed knowledge transfer and federated map reasoning
- 天然气潮流计算matlab程序
- Some simple commands
- Data formatting widget
- Difference between code signing certificate and SSL certificate
- Flink comprehensive case (IX)
- R语言tidyr包的gather函数将从宽表转化为长表(宽表转化为长表)、第一个参数指定原多个数据列名称生成的新数据列名称、第二个参数指定原表内容值、第三个和第四个参数通过列索引指定不变的列名称列表
- 简易订单管理系统小练习
- Kunyu installation details
猜你喜欢

Soft link, hard link

网络安全——文件上传竞争条件绕过

Network security - file upload competitive conditions bypass

The scroll bar in unity ugui is not displayed from the top when launching the interface in the game

uni-app 背景音频 熄屏或者退回桌面之后不在播放

游戏思考04总结:针对帧、状态、物理同步的总结(之前写的太长,现在简略下)

Rhcsa sixth note

Apache2 ha experiment with raspberry pie

网络安全——函数绕过注入

Sringboot-plugin-framework 实现可插拔插件服务
随机推荐
Network security - file upload competitive conditions bypass
通配符(泛域名)SSL证书
Flink fault tolerance mechanism (V)
An error is reported when using activiti to create a database table,
Difference between code signing certificate and SSL certificate
Aike AI frontier promotion (7.24)
Data Lake series articles
Why are there "two abstract methods" in the functional interface comparator?
论文笔记:Swin-Unet: Unet-like Pure Transformer for MedicalImage Segmentation
Network security - penetration using evil maid physical access security vulnerabilities
R语言使用epiDisplay包的summ函数计算dataframe中指定变量在不同分组变量下的描述性统计汇总信息并可视化有序点图、自定义cex.main参数配置标题文本字体的大小
2021-07-09
NOIP2021 T2 数列
Sringboot-plugin-framework 实现可插拔插件服务
Flex layout
The gather function of tidyr package of R language converts a wide table into a long table (a wide table into a long table), the first parameter specifies the name of the new data column generated by
Network security - filtering bypass injection
Flinktable & SQL (VI)
[untitled] rhcsa first operation
HCIP第十三天