首页 技术 正文
技术 2022年11月18日
0 收藏 554 点赞 3,198 浏览 1498 个字

题目

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2726

题意

飞机,一个起飞的跑道,两个降落的跑道。每个时刻首先两个跑道降落一些飞机,然后再飞走一架飞机,最后所有还停留着的飞机按照0开始编号,问如何安排能使序号最小

思路

明显,使用二分法枚举答案

感想:

由于题目描述,不太能理解到底是如何起飞,降落,序号又是何时进行统计的,所以在最后的序号上是否要多取1卡了很久

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPos;
const int MAXN = ;
int a[MAXN];
int b[MAXN];
int sumA[MAXN];
int sumB[MAXN];
int limitedA[MAXN];
int limitedB[MAXN];
int limitedSum[MAXN];
int n;
bool check(int mx) {
int costA = , costB = ;
for (int i = ; i <= n; i++) {
costA = max(costA, sumA[i] - mx);
costB = max(costB, sumB[i] - mx);
if (costA > limitedA[i] || costB > limitedB[i] || costA + costB > limitedSum[i])return false;
}
return true;
}int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
cin >> T;
for (int ti = ; ti <= T && cin >> n; ti++) {
for (int i = ; i <= n; i++) {
cin >> a[i] >> b[i];
}
//if (ti < 258)continue;
for (int i = ; i <= n; i++) {
sumA[i] = sumA[i - ] + a[i];
sumB[i] = sumB[i - ] + b[i];
bool addA = sumA[i - ] > limitedA[i - ];
bool addB = sumB[i - ] > limitedB[i - ];
limitedA[i] = limitedA[i - ] + (addA ? : );
limitedB[i] = limitedB[i - ] + (addB ? : );
limitedSum[i] = limitedSum[i - ] + ((limitedA[i] + limitedB[i] > limitedSum[i - ]) ? : );
}
int l = , r = n * ;
while (l < r) {
int mid = (l + r) >> ;
if (mid == l)break;
if (check(mid)) {
r = mid;
}
else {
l = mid;
}
}
cout<<l<<endl;
}
return ;
}
上一篇: C/C++三目运算符
下一篇: Binary Tree Path Sum
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,037
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,522
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,370
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,151
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,784
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,866