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

我真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. 抽象常量class

    需要把经常用到的常量抽象到一个类里面管理 如:

  2. Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

    Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

  3. Fixed table

    废话不多说,直接代码. <!DOCTYPE> <html> <head> <meta charset="utf-8"/> <s ...

  4. Invalid bound statement (not found): com.ros.dao.LogMapper.insert

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ros.dao.LogMapp ...

  5. django 第一次运行出错

    直接运行整个项目正常,直接运行url文件报错 报错内容: E:\Python\python.exe D:/Python储存文件/ceshiweb/ceshiweb/urls.pyTraceback ( ...

  6. websphere7.0异常:SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机

    websphere7.0错误:SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机. SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机.SRVE0255E: ...

  7. C#在透明窗体WinForm上面画图(电子尺小工具的实现)

    前几天要做一个微信调一调的外挂,里面用到了尺子测量距离,然后就自己下载了一个电子尺,最近要升级我的跳一跳外挂,然后就准备自己做一个电子尺,嵌入到我的外挂里面,在嵌入到我的外挂之前,我自己做了一个完整版 ...

  8. tp5 -- 微信公众号支付

    近来期间比较忙, 忙完之后发现最近有挺多的东西没有整理,于是乎.就将以前用到的一些小东西整理了一下. 如果对您有帮助,则是我最大的幸运. 本篇主要是说了一下整合TP5的微信公众号支付. 不过由于最近T ...

  9. javaEE(17)_邮件原理与JavaMail开发

    一.Java邮件开发介绍 为什么要学习javamail开发 •现在很多WEB应用在开发时都需要集成邮件发送功能,例如: •给新注册的用户自动发送一封包含其注册信息的欢迎E-Mail. •给过生日的注册 ...

  10. 使用iptables缓解DDOS及CC攻击

    使用iptables缓解DDOS及CC攻击 LINUX  追马  7个月前 (02-09)  465浏览  0评论 缓解DDOS攻击 防止SYN攻击,轻量级预防 iptables -N syn-flo ...