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的一些用途,我想到可以规划和团队的目标,这点让我感到很兴奋,分享学习这个软件. 学习之前,我应当把软件中的单词学明白.现在就 ...
随机推荐
- java 14-2 正则表达式的案例
1.判断功能 String类的public boolean matches(String regex) 需求: 判断手机号码是否满足要求? 分析: A:键盘录入手机号码 B:定义手机号码的规则 136 ...
- ViewPager -- Fragment 切换卡顿 性能优化
当ViewPager切换到当前的Fragment时,Fragment会加载布局并显示内容,如果用户这时快速切换ViewPager,即 Fragment需要加载UI内容,而又频繁地切换Fragment, ...
- smarty模板继承
- jenkins配置记录(2)--代码发布流程
在我们的日常运维工作中,使用jenkins来完成业务代码发版上线是至关重要的一环.前面已经提到在jenkins上添加用户权限的操作,今天重点说下如何在jenkins下构建项目工程进行代码发布? 在此简 ...
- javascript设置网页刷新或者重新加载后滚动条的位置不变
有个同事说再javascript中你可以做任何你想做的事情,当时觉得不以为然,今天遇到个问题,就是页面重新加载后总是回到页面的顶部,如果客户只想看到他想看到的部分是怎么变化的,这个体验就好了.原本想象 ...
- DevExpress主从表 按组分页一组不足一页为一页--以此记录
本文的主要是说明Dev的报表的主从表,主从表的每一组显示在一页,当一组超出一页,第二页只显示第一组的. 一.每上报表设置图 简单设计图如上 二.后台代码 报表页代码 public partial cl ...
- FormsAuthentication详解
配置安全鉴别 鉴别是指鉴定来访用户是否合法的过程.ASP.NET Framework支持三种鉴别类型: Windows鉴别: NET Passport鉴别: Forms鉴别. 对于某一特定的应用程序, ...
- SQL Server优化50法
查询速度慢的原因很多,常见如下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化 ...
- 超全!iOS 面试题汇总
之前看了很多面试题,感觉要不是不够就是过于冗余,于是我将网上的一些面试题进行了删减和重排,现在分享给大家.(题目来源于网络,侵删) 1. Object-c的类可以多重继承么?可以实现多个接口么?Cat ...
- swift第一季基础语法
同: 一.基础 同: 1常量和变量 2数据类型和数据类型转换 3别名 不同: 1可选类型optional 2BOOL类型 3元组类型 4断言Assertion 二.基本操作符 同: 1赋值和算术运算及 ...