当前位置:网站首页>CSP2021 T1 廊桥分配
CSP2021 T1 廊桥分配
2022-07-24 13:42:00 【lAWTYl】
廊桥分配
传送门:CSP2021 T1 廊桥分配
题目大意
现在有 n n n 个廊桥, m 1 m_1 m1 个国内航班和 m 2 m_2 m2 个国际航班。每一个航班包含一个进入机场的时间和一个离开机场的时间。且国内的航班只能停靠在国内区的廊桥或者遥远的停机位,国际航班同理。所有飞机优先停靠在廊桥上。
现在让你分配所有廊桥给国际区和国内区,让能停靠在廊桥的飞机的总数最大,并输出这个最大值。
分析
我们令 f [ x ] f[x] f[x] 表示国内区第 x x x 个廊桥停靠过的飞机总数, g [ x ] g[x] g[x] 表示国际区第 x x x 个廊桥停靠过的飞机总数。那么答案显然就是:
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]}
那么我们现在就要考虑的就是怎样快速求出 f f f 和 g g g 这两个数组。方法也很简单,我们每次给到达的飞机安排目前编号最小的廊桥来停靠,这样就能很简单的解决廊桥个数限制的问题。就是说分配到第 n n n 个廊桥之后再分配 n + 1 n + 1 n+1 时就相当于直接分配到遥远的停机位了,不需要做其他更多的处理。
剩下的就是模拟了。
代码
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MAXN 100100
typedef pair<int , int> pii; // 第一位是离开时间 第二位是廊桥编号
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;
}
边栏推荐
- 网络安全——Web渗透测试
- 通配符(泛域名)SSL证书
- Simple order management system small exercise
- Icml2022 | branch reinforcement learning
- Explain flex layout in detail
- exception handling
- 网络安全——WAR后门部署
- Browser failed to get cookies, browser solution
- Group knowledge map: distributed knowledge transfer and federated map reasoning
- 网络安全——文件上传内容检查绕过
猜你喜欢

Network security - penetration using evil maid physical access security vulnerabilities

Sringboot-plugin-framework 实现可插拔插件服务

Aggregation measurement of robot swarm intelligence based on group entropy

CSDN garbage has no bottom line!

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

position: -webkit-sticky; /* for Safari */ position: sticky;

网络安全——文件上传渗透测试

Paper notes: swing UNET: UNET like pure transformer for medicalimage segmentation

Network security - error injection

Explain the edge cloud in simple terms | 2. architecture
随机推荐
群体知识图谱:分布式知识迁移与联邦式图谱推理
Network security - file upload competitive conditions bypass
网络安全——报错注入
Mass data excel download - the author of this article only tried to download 510000 data, which took 7 seconds
Explain the edge cloud in simple terms | 2. architecture
【无标题】rhcsa第一次作业
Network security - filtering bypass injection
How to configure webrtc protocol for low latency playback on easycvr platform v2.5.0 and above?
Browser type judgment
如何用WebGPU流畅渲染百万级2D物体?
爱可可AI前沿推介(7.24)
交换机链路聚合详解【华为eNSP】
网络安全——文件上传白名单绕过
Packaging class (mutual conversion between types)
Browser failed to get cookies, browser solution
Repair the problem of adding device groups and editing exceptions on easycvr platform
Explain flex layout in detail
R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、设置by参数为目标变量、设置percent参数配置是否显示百分比信息
Flex layout
CSDN garbage has no bottom line!