Intervals
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 26028   Accepted: 9952

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


题意:有n个区间,每个区间有3个值,ai,bi,ci代表,在区间[ai,bi]上至少要选择ci个整数点,ci可以在区间内任意取不重复的点
现在要满足所有区间的自身条件,问最少选多少个点

一段区间,想到前缀和处理选的个数
每个前缀和建一个点
s[b]-s[a-1]>=c
同时要满足前缀和的性质,即:
s[i]-s[i-1]>=0
s[i]-s[i-1]<=1
最小值,按>=建图跑最长路
 
注意区间范围0..n,读入时改成了1...n+1(n)
但是0节点也是(前缀和!)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=5e4+,M=15e4+,INF=1e9;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,a,b,c;
struct edge{
int v,ne;
double w;
}e[M];
int h[N],cnt=;
inline void ins(int u,int v,int w){
cnt++;
e[cnt].v=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt;
}
int q[N],head,tail,inq[N],num[N],d[N];
inline void lop(int &x){if(x==N) x=;else if(x==) x=N-;}
bool spfa(){
head=tail=;
memset(inq,,sizeof(inq));
memset(num,,sizeof(num));
for(int i=;i<=n;i++) q[tail++]=i,inq[i]=,d[i]=;
while(head!=tail){
int u=q[head++];inq[u]=;lop(head);
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v,w=e[i].w;
if(d[v]<d[u]+w){
d[v]=d[u]+w;
if(!inq[v]){
inq[v]=;
if(++num[v]>n) return true;
if(d[v]>d[q[head]]) head--,lop(head),q[head]=v;
else q[tail++]=v,lop(tail);
}
}
}
}
return false;
}
int main(){
m=read();
for(int i=;i<=m;i++){
a=read()+;b=read()+;c=read();n=max(n,b);
ins(a-,b,c);
}
for(int i=;i<=n;i++) ins(i-,i,),ins(i,i-,-);
spfa();
printf("%d",d[n]);
}
 

POJ1201 Intervals[差分约束系统]的更多相关文章

  1. POJ1201 Intervals差分约束系统(最短路)

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

  2. Intervals(差分约束系统)

    http://poj.org/problem?id=1201 题意:给定n个整数闭区间[a,b]和n个整数c,求一个最小的整数集合Z,满足Z里边的数中范围在闭区间[a,b]的个数不小于c个. 思路:根 ...

  3. POJ 1201 Intervals (差分约束系统)

    题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...

  4. POJ1201 Intervals(差分约束)

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

  5. poj1201 Intervals——差分约束

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

  6. poj 1201/zoj 1508 intervals 差分约束系统

      // 思路 : // 图建好后 剩下的就和上一篇的 火烧连营那题一样了 求得解都是一样的 // 所以稍微改了就过了 // 最下面还有更快的算法 速度是这个算法的2倍#include <ios ...

  7. PKU 1201 Intervals(差分约束系统+Spfa)

    题目大意:原题链接 构造一个集合,这个集合内的数字满足所给的n个条件,每个条件都是指在区间[a,b]内至少有c个数在集合内.问集合最少包含多少个点.即求至少有多少个元素在区间[a,b]内. 解题思路: ...

  8. POJ1201 Intervals(差分约束系统)

    与ZOJ2770一个建模方式,前缀和当作点. 对于每个区间[a,b]有这么个条件,Sa-Sb-1>=c,然后我就那样连边WA了好几次. 后来偷看数据才想到这题还有两个隐藏的约束条件. 这题前缀和 ...

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

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

随机推荐

  1. 背水一战 Windows 10 (27) - 控件(文本类): TextBlock

    [源码下载] 背水一战 Windows 10 (27) - 控件(文本类): TextBlock 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) TextBlock 示例 ...

  2. php中用GD绘制折线图

    php中用GD绘制折线图,代码如下: Class Chart{ private $image; // 定义图像 private $title; // 定义标题 private $ydata; // 定 ...

  3. Idea创建Maven项目

  4. linux 共享内存 shmat,shmget,shmdt,shmctl

    shmget int shmget(key_t key, size_t size, int flag);//开辟一段共享内存 key_t key :标识符的规则() size_t size :共享内存 ...

  5. php实现设计模式之 迭代器模式

    <?php /*迭代器模式: 提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示.(行为模式) * 1.迭代器角色(Iterator):迭代器角色负责定义访问和遍历元素的 ...

  6. 工业串口和网络软件通讯平台(SuperIO 2.1)更新发布

    SuperIO 2.1下载 一.SuperIO 的特点: 1)    能够很快的构建自己的通讯平台软件,包括主程序. 2)   设备模块化开发,通过配制文件挂载,即可在平台软件下运行. 3)   设备 ...

  7. Deployment options

    Play applications can be deployed virtually anywhere: inside Servlet containers, as standalone serve ...

  8. MySQL中进行模糊搜索的一些问题

    在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符.SQL 通配符必须与 LIKE 运算符一起使用.在 SQL 中,可使用以下通配符:通配符 描述       % 替代一个或多个字符     ...

  9. ADO.NET数据库参数化

    数据库参数化传递可以增强数据的安全性,但却会降低开发效率,为此创建了如下函数以解决这个问题: public static string PrepareParameter(string sql, out ...

  10. javascript的函数

    1.函数的声明 (1) function命令方式 function fn(){}; (2) 函数的表达式 采用变量赋值的方式,function命令后面不带有函数名.如果加上函数名,那么该函数名只在函数 ...