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的一些用途,我想到可以规划和团队的目标,这点让我感到很兴奋,分享学习这个软件. 学习之前,我应当把软件中的单词学明白.现在就 ...
随机推荐
- Android--使用VideoView播放视频
承香墨影 Android--使用VideoView播放视频 前言 之前有讲过如何使用SurfaceView配合MediaPlayer播放视频,其实Android还为开发人员提供了另外一种更简单 ...
- C#中NULL,"",DBNULL,String.Empty,Convert.IsDBNull()的区别
C#中的空值的判断较麻烦,不象在VB6中那么简单,这些各种空值的判断和理解对不熟悉的人来说,可能很麻烦,现就我在使用过程中的一点体会和大家共同分享. (1)NULL null 关键字是表示不引用任何对 ...
- python中的Unittest常用方法
import unittest class SimpleUnitTest(unittest.TestCase): def test_Fail(self): self.failUnless(True) ...
- android Camera 录像时旋转角度
录像保存时,旋转角度要与所拍录像时的角度保持一致,否则,看起来就会出现角度不度,巅倒等问题. 一般在开始录像之前会先去初始化录像 initializeRecorder 中会去读取当前的录像或拍照的旋转 ...
- 查询EBS请求日志的位置和名称
select * from FND_CONCURRENT_PROGRAMS_VL fcp where fcp.USER_CONCURRENT_PROGRAM_NAME like '%CUX%XXXX% ...
- JAVA NIO是什么(zz)
JAVA NIO是什么? 1. 基本 概念 IO 是主存和外部设备 ( 硬盘.终端和网络等 ) 拷贝数据的过程. IO 是操作系统的底层功能实现,底层通过 I/O 指令进行完成. 所有语言运行时系 ...
- Tomcat简易安装指南
由于要学习activiti的使用,而activiti依赖于tomcat,所以下载了一个tomcat 7 的binary包,然后按照running.TXT中的描述来手动安装,下文主要是记录了在阅读run ...
- java资源下载之官网地址
[一].json下载地址 http://sourceforge.net/projects/json-lib/files/ [二].apache-commons下载地址 http://commons.a ...
- MVC5 + EF6 + Bootstrap3 (14) 分部视图PartialView
Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-partialview.html 系列教程:MVC5 + E ...
- EF实体框架之CodeFirst三
前两篇博客学习了数据库映射和表映射,今天学习下数据库初始化.种子数据.EF执行sql以及执行存储过程这几个知识. 一.数据库初始化策略 数据库初始化有4种策略 策略一:数据库不存在时重新创建数据库 D ...