Flying Right POJ - 3038
有一条从南到北的航线,航线上有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 ;
}
Flying Right POJ - 3038的更多相关文章
- poj 3038
http://poj.org/problem?id=3038 这个题我是在一个关于并查集的博客中找到的,结果我就觉得这个应该是个贪心,真想不出这个与并查集有什么鬼关系,看discuss里面也都是贪心, ...
- POJ 3038 贪心(multiset)
题意: 思路: 1. 贪心 我们考虑肯定是走最近的最合适 想象自己是一个黑一日游的司机: 1.如果有乘客要上车,那么就让他上,收钱! 2.如果超载了,把距目的地最远的几个乘客踢下去,退钱. 3.行驶到 ...
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- poj 并查集
http://poj.org/problem?id=1611 水题 题意:就是找一共有多少个人感染了,0是感染学生的编号. #include <stdio.h> #include < ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- poj 动态规划的主题列表和总结
此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...
随机推荐
- Android.mk用法详解
一.Android.mk介绍 Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握 ...
- Adreno Profiler 提取手机游戏资源
https://blog.csdn.net/lly20000/article/details/79774755 step.1 准备工具 1.adb连接工具(我用的cofface adb ) [cof ...
- c/c++程序设计涉及的一些知识点
c/c++程序设计涉及的一些知识点 c中的printf函数 main(){ int b = 3; int arr[]= {6,7,8,9,10}; int * ptr = arr; *(ptr++) ...
- HTML第一讲
HTML标记区分 HTML即超文本标记语言(HtyperText Markup Language),其作用就是将编辑的内容在屏幕上显示.文件的后缀为.HTML. 在HTML中成对出现的叫做双标记(譬如 ...
- Appium+python自动化27-等待activity出现(android特有的wait_activity)
前言 在启动app的时候,如果直接做下一步点击操作,经常会报错,于是我们会在启动完成的时候加sleep. 那么问题来了,这个sleep时间到底设置多少合适呢?设置长了,就浪费时间,设置短了,就会找不到 ...
- 杂项:HTML5-2/3-新元素
ylbtech-杂项:HTML5-2/3-新元素 自1999年以后HTML 4.01 已经改变了很多,今天,在HTML 4.01中的几个已经被废弃,这些元素在HTML5中已经被删除或重新定义. 为了更 ...
- ngui自适应
增加UIROOT using UnityEngine; namespace Com.Xyz.UI { [ExecuteInEditMode] [RequireComponent(typeof(UIRo ...
- STS - 配置Tomcat 运行路径
背景 今天在一台新机器上面安装开发环境,下载完code以后在STS上配置Tomcat,发现启动以后无法读取到配置文件...启动失败! 七月 , :: 上午 org.apache.catalina.co ...
- libvirt- Virsh 所有命令详单
help 打印帮助 attach-device 从一个XML文件附加装置 attach-disk 附加磁盘设备 attach-interface 获 ...
- [Cpp primer] Library vector Type
#include<vector> using std::vector; //Vector is a container. //It has a collection of same typ ...