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

我真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. uvm_driver——老司机带带我

    文件:src/comps/uvm_driver.svh类: uvm_driver uvm_driver继承(C++中叫继承)自uvm_component,其中定义了两个Ports:seq_item_p ...

  2. Oracle种常用性能监控SQL语句

    --Oracle常用性能监控SQL语句 --1 SELECT * FROM SYS.V_$SQLAREA WHERE DISK_READS > 100; --2 监控事例的等待 SELECT E ...

  3. 你不知道的HTTP之首部字段一览

    一.HTTP/1.1 首部字段一览 HTTP 首部字段根据实际用途被分为以下 4 种类型: 1.通用首部字段:请求报文和响应报文两方都会使用的首部. 首部字段名 说明 Cache-Control 控制 ...

  4. ImportError: No module named flask.ext.wtf 解决方法

    install pip install flask.ext.wtf

  5. leetcode_1049. Last Stone Weight II_[DP]

    1049. Last Stone Weight II https://leetcode.com/problems/last-stone-weight-ii/ 题意:从一堆石头里任选两个石头s1,s2, ...

  6. Resize a UIImage the right way

    When deadlines loom, even skilled and experienced programmers can get a little sloppy. The pressure ...

  7. 机器学习(3)- 学习建议<误差出现如何解决?>

    根据Andrew Ng在斯坦福的<机器学习>视频做笔记,已经通过李航<统计学习方法>获得的知识不赘述,仅列出提纲. 1 学习建议 误差太大,如何改进? 使用更多的训练样本→解决 ...

  8. Mac 安装和卸载 Mysql5.7.11 的方法

    安装 去http://www.mysql.com/downloads/, 选择最下方的MySQL Community Edition,点击MySQL Community Server的download ...

  9. JavaScript -- 语法和数据类型

    前戏 前面学了HTML和CSS相关的知识,那JavaScript是做什么的呢?你在网页上看到的那些炫酷的特效都是通过JS来实现的,所以,想要开发一个逼格满满的web页面,JS是必须要会的 什么是Jav ...

  10. 第2节 azkaban调度:16、azkaban的介绍以及azkaban的soloserver的安装使用

    2. 工作流调度器azkaban 2.1 概述 azkaban官网: https://azkaban.github.io/ 2.1.1为什么需要工作流调度系统 l  一个完整的数据分析系统通常都是由大 ...