有一条从南到北的航线,航线上有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的更多相关文章

  1. poj 3038

    http://poj.org/problem?id=3038 这个题我是在一个关于并查集的博客中找到的,结果我就觉得这个应该是个贪心,真想不出这个与并查集有什么鬼关系,看discuss里面也都是贪心, ...

  2. POJ 3038 贪心(multiset)

    题意: 思路: 1. 贪心 我们考虑肯定是走最近的最合适 想象自己是一个黑一日游的司机: 1.如果有乘客要上车,那么就让他上,收钱! 2.如果超载了,把距目的地最远的几个乘客踢下去,退钱. 3.行驶到 ...

  3. 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733

    1.POJ 1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5744   Accepted: ...

  4. poj 并查集

    http://poj.org/problem?id=1611 水题 题意:就是找一共有多少个人感染了,0是感染学生的编号. #include <stdio.h> #include < ...

  5. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  6. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  7. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  8. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

  9. poj 动态规划的主题列表和总结

    此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...

随机推荐

  1. elixir 几种安装方式

    1. yum yum 源(直接放弃,版本太老)   2. 使用预编译包 wget https://github.com/elixir-lang/elixir/releases/download/v1. ...

  2. 13.Python接口自动化测试 -- 豆瓣

    1.代码如下所示: import requests,unittest import json import HTMLTestRunner class TestDouBan(unittest.TestC ...

  3. GPS数据包格式解析

    四种定位系统:1.美国的全球定位系统(Global Positioning System,GPS)2.俄罗斯的格罗拉斯(Global Nabigation Satellite System,GLONA ...

  4. vs2012加载T4MVC模板

    (1)在工程项目上右键点击“管理NuGet程序包”,在线搜索T4MVC模板,选择并安装,安装成功后,项目中会添加T4MVC.tt文件及子文件. (2)如果添加了新的控制器,则右击T4MVC.tt文件点 ...

  5. 64位windows系统安装javaee6.0不成功解决方案

    64位windows系统安装javaee6.0不成功解决方案 (2013-01-19 14:59:51) 转载▼ 标签: 杂谈   could not find the required versio ...

  6. Eclipse中创建新的Spring Boot项目

    本文转载自:http://blog.csdn.net/clementad/article/details/51334064 简单几步,在Eclipse中创建一个新的spring Boot项目: 1.E ...

  7. Big Water Problem

    链接:https://www.nowcoder.com/acm/contest/77/B来源:牛客网 Big Water Problem 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ ...

  8. 杂项:HTML5-1/3-发展历程

    ylbtech-杂项:HTML5-1/3-发展历程 万维网的核心语言.标准通用标记语言下的一个应用超文本标记语言(HTML)的第五次重大修改(这是一项推荐标准.外语原文:W3C Recommendat ...

  9. Cassandra Wiki Login JmxSecurity

    JmxSecurity 监控和管理Cassandra

  10. 卷积神经网络之AlexNet网络模型学习

    ImageNet Classification with Deep Convolutional Neural Networks 论文理解  在ImageNet LSVRC-2010上首次使用大型深度卷 ...