我不会做贪心题啊……贪心题啊……题啊……啊……

我真TM菜爆了啊……

这题就像凌乱的yyy一样,把终点排序,终点相同的按起点排序。然后维护一个查询最大值的线段树。对于一个区间[l,r],如果这个区间已经有的最大值为s,那么这个区间最多还能装下c-s头奶牛。

当然奶牛数量没那么多的话我也是没有办法

最后说一句,奶牛到终点就下车了,可以给别的奶牛腾空间,不计入个数。所以奶牛在车上的区间为[l,r-1]。

#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 100001
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define root 1, 1, n
#define ls now << 1, l, mid
#define rs now << 1 | 1, mid + 1, r int k, n, c, ans;
int sum[N << ], add[N << ]; struct node
{
int s, t, m;
}p[N]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline bool cmp(node x, node y)
{
return x.t < y.t;
} inline void pushdown(int now)
{
if(add[now])
{
sum[now << ] += add[now];
sum[now << | ] += add[now];
add[now << ] += add[now];
add[now << | ] += add[now];
add[now] = ;
}
} inline int query(int now, int l, int r, int x, int y)
{
if(x <= l && r <= y) return sum[now];
pushdown(now);
int mid = (l + r) >> , ret = ;
if(x <= mid) ret = max(ret, query(ls, x, y));
if(mid < y) ret = max(ret, query(rs, x, y));
return ret;
} inline void update(int now, int l, int r, int x, int y, int d)
{
if(x <= l && r <= y)
{
sum[now] += d;
add[now] += d;
return;
}
pushdown(now);
int mid = (l + r) >> ;
if(x <= mid) update(ls, x, y, d);
if(mid < y) update(rs, x, y, d);
sum[now] = max(sum[now << ], sum[now << | ]);
} int main()
{
int i, x;
k = read();
n = read();
c = read();
for(i = ; i <= k; i++)
{
p[i].s = read();
p[i].t = read();
p[i].m = read();
}
std::sort(p + , p + k + , cmp);
for(i = ; i <= k; i++)
{
x = query(root, p[i].s, p[i].t - );
if(x < c)
{
update(root, p[i].s, p[i].t - , min(p[i].m, c - x));
ans += min(p[i].m, c - x);
}
}
printf("%d\n", ans);
return ;
}

【Luogu】P1607庙会班车Fair Shuttle(线段树+贪心)的更多相关文章

  1. [USACO09FEB]庙会班车Fair Shuttle 线段树维护maxx&&贪心

    题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...

  2. BZOJ 1577: [Usaco2009 Feb]庙会捷运Fair Shuttle 线段树 + 贪心

    escription 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1&l ...

  3. 洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle

    P1607 [USACO09FEB]庙会班车Fair Shuttle 题目描述 Although Farmer John has no problems walking around the fair ...

  4. 洛谷 P1607 [USACO09FEB]庙会班车Fair Shuttle 解题报告

    P1607 [USACO09FEB]庙会班车Fair Shuttle 题目描述 Although Farmer John has no problems walking around the fair ...

  5. 线段树【p1607】[USACO09FEB]庙会班车Fair Shuttle

    Description 逛逛集市,兑兑奖品,看看节目对农夫约翰来说不算什么,可是他的奶牛们非常缺乏锻炼--如果要逛完一整天的集市,他们一定会筋疲力尽的.所以为了让奶牛们也能愉快地逛集市,约翰准备让奶牛 ...

  6. 【USACO09FEB】 庙会班车 Fair Shuttle 贪心+线段树

    Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his ...

  7. Luogu P1607 庙会班车【线段树】By cellur925

    题目传送门 据说可以用贪心做?算了算了...我都不会贪.... 开始想的是用线段树,先建出一颗空树,然后输进区间操作后就维护最大值,显然开始我忽视了班车的容量以及可以有多组奶牛坐在一起的信息. 我们肯 ...

  8. 【贪心】洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle 题解

        不是很容易写出正解的贪心问题. 题目描述 Although Farmer John has no problems walking around the fair to collect pri ...

  9. P1607 [USACO09FEB]庙会班车Fair Shuttle

    题目描述 Although Farmer John has no problems walking around the fair to collect prizes or see the shows ...

随机推荐

  1. Hibernate三种批量处理数据

    概念:批量处理数据是指在一个事务场景中处理大量数据. 在应用程序中难以避免进行批量操作,Hibernate提供了以下方式进行批量处理数据: (1)使用HQL进行批量操作  数据库层面  execute ...

  2. Grace Huang 2017/1/12

    原文 Huang doesn't think of acting as pretending to be someone else.Rather,she considers it an opportu ...

  3. HDU 4276 The Ghost Blows Light (树形DP,变形)

    题意:给定一棵n个节点的树,起点是1,终点是n,每经过一条边需要消耗Ti天,每个点上有一定量的珠宝,要求必须在t天内到达终点才可以将珠宝带出去,问至多能带多少珠宝? 思路: 注意Ti可以为0,而且有可 ...

  4. Android(java)学习笔记144:网络图片浏览器的实现(ANR)

    1.我们在Android下,实现使用http协议进行网络通信,请求网络数据.这里是获取网络上的图片信息,让它可以显示在手机上: 但是我们这个手机连接网络是很费时间,如果我们在主线程(UI线程)中写这个 ...

  5. sparkmlib-相关系数

    一.基本原理 在stat包中实现了皮尔逊(Pearson)与 斯皮尔曼(Spearman)两类相关系数的计算 (1)Pearson:   (x,y)协方差/[(x标准方差)*(y标准方差)] 详情可以 ...

  6. JavaWeb项目实现图片验证码

    一.什么是图片验证码? 可以参考下面这张图: 我们在一些网站注册的时候,经常需要填写以上图片的信息. 这种图片验证方式是我们最常见的形式,它可以有效的防范恶意攻击者采用恶意工具,调用“动态验证码短信获 ...

  7. 油猴Tampermonkey 全局函数 它的注入函数都在 onload里面,直接写函数 都是内部函数,外部要是调用,就要挂靠到window上

    油猴Tampermonkey 全局函数 它的注入函数都在 onload里面,直接写函数 都是内部函数,外部要是调用,就要挂靠到window上 window.like111 = function (){ ...

  8. 标注偏置问题(Label Bias Problem)和HMM、MEMM、CRF模型比较<转>

    转自http://blog.csdn.net/lskyne/article/details/8669301 路径1-1-1-1的概率:0.4*0.45*0.5=0.09 路径2-2-2-2的概率:0. ...

  9. caffe的调试技巧 和 使用split层

    1.网络中的layer层的输出,只要没有作为其他层的输入,caffe的日志就会把这个top输出(如果你用那个网站画网络结构图,你也会发现这种情况的层的颜色是不一样的,是紫色的) 2.如果你想看某一层在 ...

  10. Evaluate|GC content|Phred|BAC|heterozygous single nucleotide polymorphisms|estimate genome size|

    (Evaluate):检查reads,可使用比对软件:使用SOAPaligner重新排列:采用massively parallel next-generation sequencing technol ...