You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.

Write a program that:

> reads the number of intervals, their endpoints and integers c1, ..., cn from the standard input,

> computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i = 1, 2, ..., n,

> writes the answer to the standard output

Input

The first line of the input contains an integer n (1 <= n <= 50 000) - the number of intervals. The following n lines describe the intervals. The i+1-th line of the input contains three integers ai, bi and ci separated by single spaces and such that 0 <= ai <= bi <= 50 000 and 1 <= ci <= bi - ai + 1.

Process to the end of file.

Output

The output contains exactly one integer equal to the minimal size of set Z sharing at least ci elements with interval [ai, bi], for each i = 1, 2, ..., n.

Sample Input

5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1

Sample Output

6

这是一个差分约束的基础题;

求最长路即可;

AC代码为:

//scanf,printf过了。cin cout T了Orz
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=1e5+;
int n,tot,S,T,u,v,w;
int dis[maxn],first[maxn],vis[maxn];
struct Node{
int v,w,net;
} edge[maxn*]; void addedge(int u,int v,int w)
{
edge[tot].v=v;
edge[tot].w=w;
edge[tot].net=first[u];
first[u]=tot++;
} void SPFA(int s)
{
queue<int> q;
memset(dis,-INF,sizeof dis);
memset(vis,,sizeof vis);
q.push(s); dis[s]=;
while(!q.empty())
{
int u=q.front(); q.pop();
vis[u]=;
for(int i=first[u];~i;i=edge[i].net)
{
if(dis[edge[i].v]<dis[u]+edge[i].w)
{
dis[edge[i].v]=dis[u]+edge[i].w;
if(!vis[edge[i].v])
{
vis[edge[i].v]=;
q.push(edge[i].v);
}
}
}
}
}
int main()
{
while(~scanf("%d",&n))
{
tot=, S=INF,T=-INF;
memset(first,-,sizeof first);
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&u,&v,&w);
S=min(S,u-),T=max(T,v);
addedge(u-,v,w);
}
for(int i=S;i<T;i++)
{
addedge(i,i+,);
addedge(i+,i,-);
}
SPFA(S);
printf("%d\n",dis[T]);
} return ;
}

HDU3870- intervals(差分约束)的更多相关文章

  1. POJ1201 Intervals(差分约束)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 10966 Description You ...

  2. hdu 1384 Intervals (差分约束)

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. poj 1716 Integer Intervals (差分约束 或 贪心)

    Integer Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12192   Accepted: 514 ...

  4. zoj 1508 Intervals (差分约束)

    Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer interva ...

  5. poj 1201 Intervals(差分约束)

    题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...

  6. poj 1201 Intervals——差分约束裸题

    题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...

  7. poj1201 Intervals——差分约束

    题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...

  8. POJ 2101 Intervals 差分约束

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27746   Accepted: 10687 Description You ...

  9. poj1201/zoj1508/hdu1384 Intervals(差分约束)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Intervals Time Limit: 10 Seconds      Mem ...

  10. hdu 1384 Intervals (差分约束)

    /* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...

随机推荐

  1. 重写(OverRide)/重载(Overload)

    方法的重写规则 参数列表必须完全与被重写方法的相同: 返回类型与被重写方法的返回类型可以不相同,但是必须是父类返回值的派生类(java5 及更早版本返回类型要一样,java7 及更高版本可以不同): ...

  2. 50行Python代码实现视频中物体颜色识别和跟踪(必须以红色为例)

    目前计算机视觉(CV)与自然语言处理(NLP)及语音识别并列为人工智能三大热点方向,而计算机视觉中的对象检测(objectdetection)应用非常广泛,比如自动驾驶.视频监控.工业质检.医疗诊断等 ...

  3. nyoj 103-A+B Problem II (python 大数相加)

    103-A+B Problem II 内存限制:64MB 时间限制:3000ms 特判: No 通过数:10 提交数:45 难度:3 题目描述: I have a very simple proble ...

  4. gitbook 入门教程之一招彻底解决 favicon 图标失效问题

    favicon-absolute 项目 favicon-absolute 插件采用绝对路径设置网站 favicon 图标,相对于相对路径来说更加简单方便.

  5. 阿里云ECS服务器部署HADOOP集群(一):Hadoop完全分布式集群环境搭建

    准备: 两台配置CentOS 7.3的阿里云ECS服务器: hadoop-2.7.3.tar.gz安装包: jdk-8u77-linux-x64.tar.gz安装包: hostname及IP的配置: ...

  6. CSS RESET —— 浏览器样式重置

    CSS Reset 1. CSS Reset为什么存在? 只要您的客户存在使用不同浏览器(ie,firefox,chrome等)的可能,那你就不得不从完美的理想状态回到现实,因为不同核心的浏览器对CS ...

  7. UML:类图关系总结

    UML类图几种关系的总结,泛化 = 实现 > 组合 > 聚合 > 关联 > 依赖在UML类图中,常见的有以下几种关系: 泛化(Generalization), 实现(Reali ...

  8. 注意android辅助服务事件不能用于保存

    本来希望把来自辅助服务的事件,像epoll那样暂存在队列进行调度,或者做成事件堆栈,从而将辅助服务事件加入到容器.但是一直不能达到预期的后果.最后才发现一个坑人的事实,辅助服务事件被释放(或者说重置) ...

  9. 使用Publisher2016快速给图片添加水印

    打开Publisher,根据图片大小及形状选择空白页面大小,此处选择纵向: 点击图标选择图片: 点击绘制文本框: 在文本框中编辑水印内容,对文字大小.字体.颜色进行调整,此处将水印颜色调整为灰色,拖动 ...

  10. python3 之 内置函数enumerate

    python3 内置函数enumerate一.简介: 该函数在字面上是枚举.列举的意思,用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列, 同时列出数据和数据下标,一般用在 for ...