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的一些用途,我想到可以规划和团队的目标,这点让我感到很兴奋,分享学习这个软件. 学习之前,我应当把软件中的单词学明白.现在就 ...
随机推荐
-
jquery简单开始
老师讲好少,我也没办法. &(function(){ 执行完所有代码之后再执行这里的代码 }) 选择器: &('#id'); 获取id &('.class'); ...
-
eclipse下项目死活不编译
工作中我们可能会遇到这种问题,项目在Eclipse下就是不编译,无论项目clean,重新build项目,重启eclipse,重启电脑都不好使.... 这时候我们可以把项目的jdk删掉,重新add一下, ...
-
Siverlight 导出Excel (经测试通过 Vs2010 ,silverlight5 )
网上搜了下,很多代码都有各种问题,自己抽时间整理了一下这个导出 using System; using System.Net; using System.Windows; using System.W ...
-
遇到的sql关键字
select count(1) 相当于 select count(*) 网上有比较差别的 菜鸟不用管
-
Android -- FragmentActivity添加Fragment的序列图
FragmentActivity添加Fragment的序列图
-
oracle问题 ORA-01843:not a valid month
解决思路: 开始解决问题走了些弯路,搜了一些资料,结果大部分说的是修改会话的nls_date_language参数 可是线上正式项目,不能说改就改吧 就找其他方式解决 最终找到问题,to_date() ...
-
jquery中$.post()方法的简单实例
在jqery中有这样一个方法,$.post()下面就这个方法做一个简单的实例: jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异 ...
-
java学习笔记21(迭代器)
java中有很多集合,内部有各种的存储的方法,取出的方法也各不相同,那么有没有一种通用的方法来取出来呢? java提供的遍历集合元素的方法有两种: 1.for-each结构(增强型for循环) 格式: ...
-
Js注释和对象
1.注释 单行: //注释内容 console.log('加油~');//在控制台输出一条信息: 多行: /*注释内容*/: 2.对象 1)对象是一个复合值,是根据某种引用类型创建出来的实例. 2)常 ...
-
jmeter 性能分析 (一点点加)
1.聚合报告 我们可以看到,通过这份报告我们就可以得到通常意义上性能测试所最关心的几个结果了. Samples -- 本次场景中一共完成了多少个Transaction Average -- 平均响应时 ...