当前位置:网站首页>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;
}
边栏推荐
- No response to NPM instruction
- Group intelligence decision-making in an open environment: concepts, challenges and leading technologies
- Flink comprehensive case (IX)
- Flink综合案例(九)
- 为什么函数式接口 Comparator 中有 “两个抽象方法”?
- Data modification and insertion
- Flink高级特性和新特性(八)
- Paper notes: swing UNET: UNET like pure transformer for medicalimage segmentation
- 微信小程序 TODO案例
- Network security - Web penetration testing
猜你喜欢

Network security - Web penetration testing

2022.7.22 模拟赛

How to quickly wrap lines in Excel table

网络安全——Web渗透测试

网络安全——服务漏洞扫描与利用

Group knowledge map: distributed knowledge transfer and federated map reasoning

Why are there "two abstract methods" in the functional interface comparator?
![[untitled]](/img/67/793d1fd7c295f0af9f683ffa389757.png)
[untitled]

WSDM 22 | graph recommendation based on hyperbolic geometry

Game thinking 04 summary: a summary of frame, state and physical synchronization (it was too long before, and now it's brief)
随机推荐
网络安全——Cookie注入
Statistical table of competition time and host school information of 2022 national vocational college skills competition (the second batch)
Adjust the array order so that odd numbers precede even numbers
Network security - file upload blacklist bypass
通配符(泛域名)SSL证书
Swarm intelligence collaborative obstacle avoidance method inspired by brain attention mechanism
数据湖系列文章
uni-app 背景音频 熄屏或者退回桌面之后不在播放
2022年全国职业院校技能大赛赛项比赛时间、承办校信息统计表(第二批)
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间
【无标题】
R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、设置by参数为目标变量、设置percent参数配置是否显示百分比信息
Add an element to the object array with unshift
22-07-23周总结
JQ remove an element style
【无标题】rhcsa第一次作业
Overview of multi view learning methods based on canonical correlation analysis
SQL Server 启停作业脚本
Matlab program for natural gas flow calculation
Group intelligence decision-making in an open environment: concepts, challenges and leading technologies