Intervals
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 22503   Accepted: 8506

Description

You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.
Write a program that:

reads the number of intervals, their end points 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 <= 50000) --
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 <= 50000
and 1 <= ci <= bi - ai+1.

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

Source

 
设   s[i]表示集合中小于等于i的元素个数,  u   v   w      s[v]-s[u-1]>=w;
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
using namespace std;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; struct edge
{
int u,v,w;
}edges[*MS]; int maxv,minv;
int dis[MS];
int esize,n; bool bellman()
{
memset(dis,,sizeof(dis));
bool flag=true;
int cnt=;
while(flag)
{
flag=false; //表示没有更新了 if(cnt++>n) //更新次数大于n-1,
return false;
for(int i=;i<esize;i++)
{
if(dis[edges[i].u]+edges[i].w<dis[edges[i].v])
{
dis[edges[i].v]=dis[edges[i].u]+edges[i].w;
flag=true;
}
} //0<=s[i]-s[i-1]<=1 这些边可以不用存储 // i-1 -->i 1 for(int i=minv;i<=maxv;i++)
{
if(dis[i-]+<dis[i])
{
dis[i]=dis[i-]+;
flag=true;
}
} // i--> i-1 0 for(int i=maxv;i>=minv;i--)
{
if(dis[i]<dis[i-])
{
dis[i-]=dis[i];
flag=true;
}
}
}
return true;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
int u,v,w;
esize=;
maxv=;
minv=INF;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&u,&v,&w);
// s[i]表示集合中小于等于i的元素个数
//s[v]-s[u-1]>=w; v->u-1 -w;
edges[esize].u=v;
edges[esize].v=u-;
edges[esize++].w=-w;
if(v>maxv)
maxv=v;
if(u<minv)
minv=u;
}
bellman();
printf("%d\n",dis[maxv]-dis[minv-]);
}
return ;
}
 
 

Intervals poj 1201 差分约束系统的更多相关文章

  1. Intervals POJ - 1201 差分约束

    You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...

  2. poj 1201 差分约束

    http://www.cnblogs.com/wangfang20/p/3196858.html 题意: 求集合Z中至少要包含多少个元素才能是每个区间[ai,bi]中的元素与Z中的元素重合个数为ci. ...

  3. POJ 1201 差分约束+SPFA

    思路: 差分约束,难在建图.(我是不会告诉你我刚学会SPFA的...) 把每个区间的ai–>bi连一条长度为ci的边. k–>k+1连一条长度为0的边. k+1–>k连一条长度为-1 ...

  4. POJ 1201 差分约束(集合最小元素个数)

    题意:       给你一个集合,然后有如下输入,a ,b ,c表示在范围[a,b]里面有至少有c个元素,最后问你整个集合最少多少个元素. 思路:       和HDU1384一模一样,首先这个题目可 ...

  5. 【POJ 1201】 Intervals(差分约束系统)

    [POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: ...

  6. 【POJ 1716】Integer Intervals(差分约束系统)

    id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS   Memory L ...

  7. poj 1201 Intervals(差分约束)

    做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,500 ...

  8. POJ 1201 Intervals(图论-差分约束)

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20779   Accepted: 7863 Descri ...

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

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

随机推荐

  1. Active Record快速入门指南

    一.概述 Active Record(中文名:活动记录)是一种领域模型模式,特点是一个模型类对应关系型数据库中的一个表,而模型类的一个实例对应表中的一行记录.关系型数据库往往通过外键来表述实体关系,A ...

  2. MacOSX快捷键

    [MacOSX快捷键] 关闭显示器:Shift + Ctrl + 退出键 休眠:Command + Option + 退出键 关机:Ctrl + Option + Command + 退出键 打开文件 ...

  3. [原创]Devexpress XtraReports 系列 10 创建标签报表

    今天这篇是Dx Reports 基础初级系列的最后一篇了.以后如果有什么高级的应用,应该另开一个中级使用系列. 昨天发表了Devexpress XtraReports系列第九篇[原创]Devexpre ...

  4. js 控制 table style css

    var table = objj.getElementsByTagName('table'); alert(table[i].width); if(table==null) return; for(v ...

  5. 使用logmnr方法找回被误删除Oracle的数据的脚本

    俗话说,常在河边走,哪有不湿鞋的.作为一个经常与数据库打交道的程序员,偶尔不小心误删除或误操作的数据也是在所难免的.如果是Oracle数据库,这里给您介绍一种从日志中找回数据的办法,下面这个地址是我以 ...

  6. POJ 3617 Best Cow Line (贪心)

    题意:给定一行字符串,让你把它变成字典序最短,方法只有两种,要么从头部拿一个字符,要么从尾部拿一个. 析:贪心,从两边拿时,哪个小先拿哪个,如果一样,接着往下比较,要么比到字符不一样,要么比完,也就是 ...

  7. shutdown 和closesocket

    来,咱们彻底的来讨论一下这个shutdown   和closesocket 从 函数调用上来分析(msdn):一旦完成了套接字的连接,应当将套接字关闭,并且释放其套接字句柄所占用的所有资源.真正释放一 ...

  8. Java的初步认识

    PS:弥补那些错过的时间,弥补那些本是决定做而没有做的事情,当初说好了学习编程要把自己学到的或是理解的写到博客中记录下来,可是由于各种缘由最终是没有实现...经过几番周折决定把那些丢掉的重新捡起来.对 ...

  9. hdu 1861-游船出租

    游船出租                                                                                   Time Limit: 1 ...

  10. Flex利用titleIcon属性给Panel容器标题部添加一个ICON图标

    Flex利用titleIcon属性,给Panel容器标题部添加一个ICON图标. 让我们先来看一下Demo(可以右键View Source或点击这里察看源代码): 下面是完整代码(或点击这里察看): ...