有一条从南到北的航线,航线上有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 ;
}

最新文章

  1. Lucene.net初探
  2. hadoop 集群 加入一个新的存储节点和删除一个计算节点需要刷新集群状态命令
  3. Hbase Shell常用命令
  4. 系统镜像以及微PE工具箱
  5. Zedboard VmodCAM PIN Constraint
  6. 【InversionCount 逆序对数 + MergeSort】
  7. Catalog和Schema
  8. BZOJ 1787: [Ahoi2008]Meet 紧急集合( 树链剖分 )
  9. json转String 和 String转json 和判断对象类型
  10. mysql声明摘要
  11. HTTP工作原理
  12. [html5] 学习笔记-Canvas应用
  13. C#常忘语法笔记(C#程序设计基础1-4章)
  14. gcc update in centos to 6.3 by scl
  15. linux_shell自定义命令
  16. Numpy学习50例
  17. PostgreSQL的autovacuum 与 vacuum full
  18. hdu 1242 Rescue(BFS入门)
  19. 在jsp里面不要瞎用&lt;!-- --&gt;注释
  20. c++ vector反转reverse

热门文章

  1. 配置 VS Code 调试 JavaScript
  2. python模块--hashlib
  3. Git 的分支和标签规则
  4. 【常见Web应用安全问题】---4、Directory traversal
  5. (二)Fiddler抓取Firefox、Chrome浏览器上的https协议
  6. RK3288 usb 摄像头旋转
  7. Android 从上层到底层-----kernel层
  8. .NET实现多个不同有效时间Session方案思考
  9. quartz报错 Couldn&#39;t retrieve job because the BLOB couldn&#39;t be deserialized: null
  10. 深入浅出 Java Concurrency (15): 锁机制 part 10 锁的一些其它问题