Cleaning Shifts
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2743   Accepted: 955

Description

Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn. 



Farmer John has N (1 <= N <= 10,000) cows who are willing to do some cleaning. Because dust falls continuously, the cows require that the farm be continuously cleaned during the workday, which runs from second number M to second number E during the day (0 <=
M <= E <= 86,399). Note that the total number of seconds during which cleaning is to take place is E-M+1. During any given second M..E, at least one cow must be cleaning. 



Each cow has submitted a job application indicating her willingness to work during a certain interval T1..T2 (where M <= T1 <= T2 <= E) for a certain salary of S (where 0 <= S <= 500,000). Note that a cow who indicated the interval 10..20 would work for 11
seconds, not 10. Farmer John must either accept or reject each individual application; he may NOT ask a cow to work only a fraction of the time it indicated and receive a corresponding fraction of the salary. 



Find a schedule in which every second of the workday is covered by at least one cow and which minimizes the total salary that goes to the cows.

Input

Line 1: Three space-separated integers: N, M, and E. 



Lines 2..N+1: Line i+1 describes cow i's schedule with three space-separated integers: T1, T2, and S.

Output

Line 1: a single integer that is either the minimum total salary to get the barn cleaned or else -1 if it is impossible to clean the barn.

Sample Input

3 0 4
0 2 3
3 4 2
0 0 1

Sample Output

5

Hint

Explanation of the sample: 



FJ has three cows, and the barn needs to be cleaned from second 0 to second 4. The first cow is willing to work during seconds 0, 1, and 2 for a total salary of 3, etc. 



Farmer John can hire the first two cows.

给出n个小区间[l,r],更新这段区间的代价为c,求覆盖一段区间[m,e]的最小值。

线段树+DP

首先应该将小区间排个序,对于每一个区间[l,r],它能够在[l-1,r]区间上覆盖,找到这段区

间的最小代价。最小代价加上这段区间的代价与r点的代价比較。更新包括r点的区间

段就能够了。

区间查询用线段树。

代码:

//94ms
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=100000+100;
const int inf=199999999;
struct node
{
int minc;
} tree[maxn<<2];
struct Cow
{
int l;
int r;
int c;
} cow[maxn];
bool cmp(Cow a,Cow b)
{
if(a.l==b.l)
return a.r<b.r;
return a.l<b.l;
}
void build(int rt,int l,int r)//建树
{
tree[rt].minc=inf;
if(l==r)
return;
int m=(l+r)>>1;
build(rt<<1,l,m);
build(rt<<1|1,m+1,r);
}
void update(int rt,int k,int v,int l,int r)//更新所有包括k的区间
{
if(l==r)
{
tree[rt].minc=min(tree[rt].minc,v);
return;
}
int m=(l+r)>>1;
if(k<=m)
update(rt<<1,k,v,l,m);
else
update(rt<<1|1,k,v,m+1,r);
tree[rt].minc=min(tree[rt<<1].minc,tree[rt<<1|1].minc);
}
int query(int rt,int l,int r,int L,int R)//查找L,R区间内的最小值
{
if(l>=L&&r<=R)
return tree[rt].minc;
int mid=(l+r)>>1;
int temp = inf;
if(L<=mid)
temp=query(rt<<1,l,mid,L,R);
if(R>mid)
temp=min(temp,query(rt<<1|1,mid+1,r,L,R));
return temp;
}
int main()
{
int n,m,e;
while(~scanf("%d%d%d",&n,&m,&e))
{
for(int i=0; i<n; i++)
scanf("%d%d%d",&cow[i].l,&cow[i].r,&cow[i].c);
int sign=1;
sort(cow,cow+n,cmp);
build(1,m-1,e);
int cur=m-1;
update(1,cur,0,m-1,e);//将m-1点赋为0.
for(int i=0; i<n; i++)
{
if(cow[i].l>cur+1)//不能所有覆盖
{
sign=0;
break;
}
int temp=query(1,m-1,e,cow[i].l-1,cow[i].r);
update(1,cow[i].r,temp+cow[i].c,m-1,e);
cur=max(cur,cow[i].r); }
if(sign)
printf("%d\n",query(1,m-1,e,e,e));
else
printf("-1\n");
}
return 0;
}

poj 3171 Cleaning Shifts(区间的最小覆盖价值)的更多相关文章

  1. POJ 3171 Cleaning Shifts(DP+zkw线段树)

    [题目链接] http://poj.org/problem?id=3171 [题目大意] 给出一些区间和他们的价值,求覆盖一整条线段的最小代价 [题解] 我们发现对区间右端点排序后有dp[r]=min ...

  2. POJ 2376 Cleaning Shifts 区间覆盖问题

    http://poj.org/problem?id=2376 题目大意: 给你一些区间的起点和终点,让你用最小的区间覆盖一个大的区间. 思路: 贪心,按区间的起点找满足条件的并且终点尽量大的. 一开始 ...

  3. POJ 3171 Cleaning Shifts

    Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. Th ...

  4. POJ 2376 Cleaning Shifts(轮班打扫)

    POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Farmer ...

  5. POJ - 2376 Cleaning Shifts 贪心(最小区间覆盖)

    Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some clea ...

  6. poj 2376 Cleaning Shifts 贪心 区间问题

    <pre name="code" class="html"> Cleaning Shifts Time Limit: 1000MS   Memory ...

  7. poj 2376 Cleaning Shifts 最小区间覆盖

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40751   Accepted: 9871 ...

  8. poj 2376 Cleaning Shifts

    http://poj.org/problem?id=2376 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  9. POJ 2376 Cleaning Shifts 贪心

    Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...

随机推荐

  1. webservice拦截器 查看消息包(soap)

    服务端: 1.获取EndpointImpl对象 2.调用EndpointImpl对象中的方法获取In拦截器 3.调用EndpointImpl对象中的方法获取out拦截器 4.添加自己的In拦截器与Ou ...

  2. 《Python 二三事》——python学习必看(转载)

        面向初学者介绍Python相关的一些工具,以及可能遇到的常见问题. 原文出处 原文作者:八八年出生的男性,互联网上常用id是 jagttt .目前正从事 IT 行业的工作.业余爱好是动漫游加电 ...

  3. Javascript闭包函数快速上手

    闭包函数是什么?在开始学习的闭包的时候,大家很能都比较难理解.就从他的官方解释来说,都是比较概念化的. 不过我们也还是从闭包的含义出发. 闭包是指函数有自由独立的变量.换句话说,定义在闭包中的函数可以 ...

  4. @import————————css代码内部链接另外css

    在css代码里这样可以链接另外的css @import url("style.css");   @import语法结构 @import + 空格+ url(CSS文件路径地址); ...

  5. 张江在线APP演示

    app下载地址:https://itunes.apple.com/cn/app/zhang-jiang-zai-xian/id722630317?mt=8

  6. 实战EntityFramework

    删除对象一定要在同一个context 我尝试这在两个方法中使用两个context(Container)实例来进行一个获得一个删除,结果我获得的”The object cannot be deleted ...

  7. KVO/KVC总结

    KVO/KVC总结       下面是根据网上文章的总结,方便查看. 在网上看别人的文章,了解KVC.KVO,有个kvo-kvc的例子,就是改变数组的内容(插入和删除),同步改变tableview中的 ...

  8. Node.js入门实例程序

    在使用Node.js创建实际“Hello, World!”应用程序之前,让我们看看Node.js的应用程序的部分.Node.js应用程序由以下三个重要组成部分: 导入需要模块: 我们使用require ...

  9. Hadoop完全分布式集群安装

    转载请注明原地址,谢谢! 本文目的是教大家配置Hadoop的完全分布式的集群,除了完全分布式还有两种分别是单节点和伪分布式部署.伪分布式只需要一台虚拟机,配置的东西也相对较少,大多用作代码调试,大家稍 ...

  10. 【Java】WSDL 简介

    WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问. 什么是 WSD ...