POJ3038 Flying Right
Description
They need your help to decide which passengers to carry each day.
Each of N (1 <= N <= 10,000) farms numbered 1..N along the coast
contains an airport (Farm 1 is northern-most; farm N is southern-most).
On this day, K (1 <= K <= 50,000) groups of cows wish to
travel.Each group of cows wants to fly from a particular farm to another
particular farm. The airline, if it wishes, is allowed to stop and
pick up only part of a group. Cows that start a flight, however,must
stay on the plane until they reach their destination.
Given the capacity C (1 <= C <= 100) of the airplane and the
groups of cows that want to travel, determine the maximum number of cows
that the airline can fly to their destination.
Input
* Lines 2..K+1: Each line contains three space-separated integers S,
E, and M that specify a group of cows that wishes to travel. The M (1
<= M <= C) cows are currently at farm S and want to travel to farm
E (S != E).
Output
Line 1: The maximum number of cows that can be flown to their
destination. This is the sum of the number of cows flown to
their destination on the flight southward in the morning plus the number
of cows flown to their destination on the flight northward in the
evening.
Sample Input
4 8 3
1 3 2
2 8 3
4 7 1
8 3 2
Sample Output
6
Hint
Four groups of cows, eight farms, and three seats on the plane.
OUTPUT DETAILS:
In the morning, the flight takes 2 cows from 1->3, 1 cow from
2->8,and 1 cow from 4->7. In the evening, the flight takes 2 cows
from 8->3.
Source
//It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int MAXK = ;
const int MAXC = ;
const int MAXN = ;
int k,n,C,ans;
int cnt,cnt2;
int total;
struct Niu{
int l,r,w;
}cow[MAXK],cow2[MAXK];
struct plane{
int to;
int num;
}a[MAXK],tmp[MAXK]; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
}
inline bool cmpl(Niu q,Niu qq){ return q.l<qq.l; }
inline bool cmpr(Niu q,Niu qq){ return q.l>qq.l; }
inline bool cmp(plane q,plane qq){ return q.to<qq.to; }
inline bool ccmp(plane q,plane qq){ return q.to>qq.to; } inline void work(){
k=getint(); n=getint(); C=getint(); int x,y;
for(int i=;i<=k;i++) {
x=getint(); y=getint();
if(x<y) cow[++cnt].l=x,cow[cnt].r=y,cow[cnt].w=getint();
else cow2[++cnt2].l=x,cow2[cnt2].r=y,cow2[cnt2].w=getint();
}
sort(cow+,cow+cnt+,cmpl);
int now=; int lin,remain;
for(int i=;i<=n;i++) {
lin=;
for(int j=;j<=total;j++) {
if(a[j].to==i) ans+=a[j].num;
else tmp[++lin]=a[j];
}
for(int j=now;j<=cnt;j++) {
if(cow[j].l==i) tmp[++lin].to=cow[j].r,tmp[lin].num=cow[j].w,now++;
else break;
}
sort(tmp+,tmp+lin+,cmp); total=; remain=C;
for(int j=;j<=lin;j++) {
if(tmp[j].num>=remain) { a[++total]=tmp[j]; a[total].num=remain; remain=; break; }
else remain-=tmp[j].num,a[++total]=tmp[j];
}
} sort(cow2+,cow2+cnt2+,cmpr);
now=; total=;
for(int i=n;i>=;i--) {
lin=;
for(int j=;j<=total;j++) {
if(a[j].to==i) ans+=a[j].num;
else tmp[++lin]=a[j];
}
for(int j=now;j<=cnt2;j++) {
if(cow2[j].l==i) tmp[++lin].to=cow2[j].r,tmp[lin].num=cow2[j].w,now++;
else break;
}
sort(tmp+,tmp+lin+,ccmp); total=; remain=C;
for(int j=;j<=lin;j++) {
if(tmp[j].num>=remain) { a[++total]=tmp[j]; a[total].num=remain; remain=; break; }
else remain-=tmp[j].num,a[++total]=tmp[j];
}
}
printf("%d",ans);
} int main()
{
work();
return ;
}
POJ3038 Flying Right的更多相关文章
- PDF 生成插件 flying saucer 和 iText
最近的项目中遇到了需求,用户在页面点击下载,将页面以PDF格式下载完成供用户浏览,所以上网找了下实现方案. 在Java世界,要想生成PDF,方案不少,所以简单做一个小结吧. 在此之前,先来勾画一下我心 ...
- hdu---(1800)Flying to the Mars(trie树)
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- HDU 5515 Game of Flying Circus 二分
Game of Flying Circus Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- about building flying sauser
download flying sauser: unzip flyingsaucer-master.zip cd flyingsaucer-master/ mvn install
- hdu 1800 Flying to the Mars
Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...
- 关于flying框架
开发10多年了,开发过程中遇到的最大的问题: ①项目的代码越来越多了,越来越复杂了,而客户的需求,你还不得不往里面加入新代码. ②开发了很多项目,每次复用时却只能把代码copy来copy去,然后调试. ...
- 数论 C - Aladdin and the Flying Carpet
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...
- 学习flying logic
之前在知乎上结识的朋友吴笛,他的qq空间里分享了 flying logic的一些用途,我想到可以规划和团队的目标,这点让我感到很兴奋,分享学习这个软件. 学习之前,我应当把软件中的单词学明白.现在就 ...
随机推荐
- mysql学习书籍推荐
1.<MySQL技术内幕:SQL编程>2.<高性能MySQL>3.<MySQL技术内幕>4. mysql技术内幕.innodb存储引擎
- man 在线手册
http://man7.org/linux/man-pages/man3/fwrite.3.html
- View (二) 自定义属性
主要有三种方法可以实现自定义属性. 方法一:不使用命名空间,不使用attrs.xml文件.通过attrs.getAttributeResourceValue方法拿到属性值 方法二: 使用命名空间, 不 ...
- Android开发EditText属性
Android开发EditText属性 EditText继承关系:View-->TextView-->EditText EditText的属性很多,这里介绍几个:android:hint= ...
- RDLC系列之二 子报表
本文实现简单的子报表 一.效果图
- 混合语言编程:启用CLR(公共语言运行时编译)让C#调用C++
前言 关于混合C#和C++的编程方式,本人之前写过一篇博客(参见混合语言编程:C#使用原生的Directx和OpenGL),在之前的博客中,介绍了在C#的Winform和WPF下使用原生的Direct ...
- Linux 字符集转化
命令行"iconv --list" 查看Linux操作系统支持的字符集 iconv_open 设置字符集转化 --iconv_t iconv_open(const char *to ...
- 事务的四个特性-ACID
事务是恢复和并发控制的基本单位. 事务应该具有4个属性:原子性.一致性.隔离性.持久性.这四个属性通常称为ACID特性. 原子性(atomicity):一个事务是一个不可分割的工作单位,事务中 ...
- MVC5 + EF6 + Bootstrap3 (14) 分部视图PartialView
Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-partialview.html 系列教程:MVC5 + E ...
- TableCell高度的控制
TableCell高度的控制 计算并指定行高rowHeight 强制指定:self.tableView.rowHeight = 88 或实现UITableViewDelegate.tableView( ...