当前位置:网站首页>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;
}
边栏推荐
- Network security - penetration using evil maid physical access security vulnerabilities
- position: -webkit-sticky; /* for Safari */ position: sticky;
- Chapter VI bus
- SQL Server 启停作业脚本
- Network security -- man in the middle attack penetration test
- Ggarrange function of R language ggpubr package combines multiple images and annotates them_ Figure add annotation, annotation, annotation information for the combined image, and add annotation inform
- Flink fault tolerance mechanism (V)
- 【无标题】rhcsa第一次作业
- Flink综合案例(九)
- How to generate expected data? Emory University and others' latest "deep learning controllable data generation" review, 52 page PDF, covering 346 documents, comprehensively expounds the controllable g
猜你喜欢
随机推荐
rhce第一次作业
Uni app background audio will not be played after the screen is turned off or returned to the desktop
自动化运维之Ansible安装部署
三层交换机配置MSTP协议详解【华为eNSP实验】
The scroll bar in unity ugui is not displayed from the top when launching the interface in the game
RHCE first operation
R语言tidyr包的gather函数将从宽表转化为长表(宽表转化为长表)、第一个参数指定原多个数据列名称生成的新数据列名称、第二个参数指定原表内容值、第三个和第四个参数通过列索引指定不变的列名称列表
Flink comprehensive case (IX)
【无标题】rhcsa第一次作业
HCIP第十三天
Nessus安全测试工具使用教程
One problem encountered:
Editor formula
Flink容错机制(五)
R语言使用sort函数排序向量数据实战、返回实际排序后的数据(默认升序)
Packet switching and label switching in MPLS
Soft link, hard link
Flink advanced features and new features (VIII) V2
Flink高级特性和新特性(八)v2
The R language uses the sort function to sort vector data and return the actually sorted data (ascending by default)









