Flying Right POJ - 3038
2024-10-18 00:09:35
有一条从南到北的航线,航线上有N个机场1-n从南到北分布,每天早上飞机从1飞到n,傍晚从n飞到1。有k组乘客,他们数量为M[k],从S飞到E,飞机上只有C个座位,计算每天飞机最多能拉多少乘客
贪心可以解决这个问题~(我一开始一直在想dp(lll¬ω¬))
每个站点让所有乘客都上飞机,如果此时超载了,那么就让目的地离当前站点最远的乘客下飞机。可以用优先队列来维护。
emmm这个代码来自 https://blog.csdn.net/severus_qin/article/details/18956647,侵删
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int maxn = ;
struct event{
int t, c;
event(){}
event(int a, int b) : t(a), c(b){}
bool operator < (const event &rhs)const{
return t < rhs.t;
}
};
vector<event> v1[maxn], v2[maxn];
int k, n, c, num[][maxn], ans;
int work(vector<event> vv[], int k){
priority_queue<event> que;
int res = , tmp = ;
for (int i = ; i <= n; i++){
res += num[k][i];
tmp -= num[k][i];
for (int j = ; j < vv[i].size(); j++){
tmp += vv[i][j].c;
que.push(vv[i][j]);
}
while(tmp > c){
event tt = que.top(); que.pop();
if (tmp - c >= tt.c){
tmp -= tt.c;
num[k][tt.t] -= tt.c;
}else{
num[k][tt.t] -= (tmp - c);
tt.c -= (tmp - c);
tmp = c;
que.push(tt);
}
}
}
return res;
}
void solve(){
memset(num, , sizeof(num));
for (int i = ; i < maxn; i++){
v1[i].clear(); v2[i].clear();
}
for (int i = ; i < k; i++){
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
if (x < y){
v1[x].push_back(event(y, z));
num[][y] += z;
}else{
x = n - x + ; y = n - y + ;
v2[x].push_back(event(y, z));
num[][y] += z;
}
}
ans = ;
ans += work(v1, ); ans += work(v2, );
printf("%d\n", ans);
return;
}
int main(){
while(scanf("%d%d%d", &k, &n, &c) == ) solve();
return ;
}
最新文章
- Lucene.net初探
- hadoop 集群 加入一个新的存储节点和删除一个计算节点需要刷新集群状态命令
- Hbase Shell常用命令
- 系统镜像以及微PE工具箱
- Zedboard VmodCAM PIN Constraint
- 【InversionCount 逆序对数 + MergeSort】
- Catalog和Schema
- BZOJ 1787: [Ahoi2008]Meet 紧急集合( 树链剖分 )
- json转String 和 String转json 和判断对象类型
- mysql声明摘要
- HTTP工作原理
- [html5] 学习笔记-Canvas应用
- C#常忘语法笔记(C#程序设计基础1-4章)
- gcc update in centos to 6.3 by scl
- linux_shell自定义命令
- Numpy学习50例
- PostgreSQL的autovacuum 与 vacuum full
- hdu 1242 Rescue(BFS入门)
- 在jsp里面不要瞎用<;!-- -->;注释
- c++ vector反转reverse
热门文章
- 配置 VS Code 调试 JavaScript
- python模块--hashlib
- Git 的分支和标签规则
- 【常见Web应用安全问题】---4、Directory traversal
- (二)Fiddler抓取Firefox、Chrome浏览器上的https协议
- RK3288 usb 摄像头旋转
- Android 从上层到底层-----kernel层
- .NET实现多个不同有效时间Session方案思考
- quartz报错 Couldn&#39;t retrieve job because the BLOB couldn&#39;t be deserialized: null
- 深入浅出 Java Concurrency (15): 锁机制 part 10 锁的一些其它问题