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的一些用途,我想到可以规划和团队的目标,这点让我感到很兴奋,分享学习这个软件. 学习之前,我应当把软件中的单词学明白.现在就 ...
随机推荐
- Maven简介与简单使用
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具.由于 Maven 的缺省构建 ...
- 运维工作中常用到的几个rsync同步命令
作为一个运维工程师,经常可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能.说到“同步”,不得不提的利器就是rsync. 下面结合本人近几年运维工作中对这一 ...
- 对window的认识
首先要明确: 不管是全局的函数还是全局的变量,都是属于window的,例如: a = 12; //全局变量 alert(a) === alert(window.a) function show(){ ...
- Gradle多项目构建
1. 创建项目 首先创建项目,名称为 test: mkdir test && cd test gradle init 这时候的项目结构如下: ➜ test tree . ├── bui ...
- U3D Debug.log的问题
今天在测试有yield有关的问题时,发现Debug.log()是异步输出机制.不一定会在调用后立即执行. 在C++有类似问题:std::cout 也不一定会立即输出,加上"\n"或 ...
- (转载)关于Apache 的两种工作模式
今天在查看服务器的时候,发现服务器http请求数 每天增长越来越多,在优化集群服务器的时候,查看到Apache 的工作模式是prefork,于是想到了worker 模式, 想暂时的把当前运行模式改成w ...
- 多个相同jar存在时的引用顺序
起因:今天一个aar包在测试环境中正常运行,使用soapui测试正常返回,在本地环境中运行则老是报数据库连接异常,经检查,是因为在运行时环境中缺少ojdbc相关的jar包引起的. 重新打了一个aar包 ...
- 微信公众平台开发之微信access_token如何有效长期保存
随着微信使用越来越广泛,微信公众平台开放了许多接口以提供更多个性化的服务,包括自定义菜单接口.客服接口.获取用户信息接口.用户分组接口.群发接口等,开发者在调用这些接口时,都需要传入一个相同的参数ac ...
- jquery-lazyload延迟加载图片 及 加载顺序 bug 修复
jquery-lazyload延迟加载图片 代码修改片段 function update() { var counter = 0; /**fix by weiyj start***/ elemen ...
- GDB堆栈跟踪与汇编调试
GDB堆栈跟踪与汇编调试 堆栈跟踪 源代码: 对预先编写的 stack.c 文件进行编译,并且使用 CGDB 进行调试,对堆栈进行跟踪,了解该代码堆栈是如何变化的. 在 CGDB 中,先设置 main ...