Intervals
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 24099   Accepted: 9159

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

  
 #include <iostream>
#include <cstdio>
#include <cstring>
#define inf 0x7ffffff
using namespace std;
const int maxn=;
const int maxm=;
int cnt,fir[maxn],to[maxm],val[maxm],nxt[maxm],dis[maxn],vis[maxn];
void addedge(int a,int b,int v)
{
nxt[++cnt]=fir[a];
to[cnt]=b;
val[cnt]=v;
fir[a]=cnt;
}
int q[maxm],front,back;
void Spfa(int S,int T)
{
fill(dis,dis+S+,inf);
q[front=]=S;back=;
vis[S]=;
dis[S]=;
while(front<back)
{
int node=q[front++];vis[node]=false;
for(int i=fir[node];i;i=nxt[i]){
if(dis[to[i]]<=dis[node]+val[i])continue;
dis[to[i]]=dis[node]+val[i];
if(!vis[to[i]])
q[back++]=to[i];
vis[to[i]]=true;
}
}
} int main()
{
int n,maxl=;
while(~scanf("%d",&n)){
memset(fir,,sizeof(fir));
cnt=;maxl=;
for(int i=;i<=n;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
addedge(b,a-,-c);
maxl=max(maxl,b);
}
for(int i=;i<=maxl;i++){
addedge(i-,i,);
addedge(i,i-,);
}
Spfa(maxl,);
printf("%d\n",-dis[]);
}
}

图论(差分约束系统):POJ 1201 Intervals的更多相关文章

  1. 图论--差分约束--POJ 1201 Intervals

    Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30971 Accepted: 11990 Descripti ...

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

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

  3. poj 1201 Intervals(差分约束)

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

  4. POJ 1201 Intervals(差分约束 区间约束模版)

    关于差分约束详情可阅读:http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html 题意: 给定n个区间[L,R], 每个区间至 ...

  5. POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束

    POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...

  6. poj 1201 Intervals 解题报告

    Intervals Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Submit Statu ...

  7. POJ 1201 Intervals

    题意:有n个区间[a,b],每个区间有一个值c.找一个集合中的元素使得每个区间至少有c个元素在这个集合中,问最小的集合大小. 思路:设d[i+1]表示0到i有多少个数在这个集合中,显然对于每个区间,d ...

  8. zoj 1508 poj 1201 Intervals

    差分约束系统. #include<cstdio> #include<cstring> #include<cmath> #include<vector> ...

  9. 图论--差分约束--POJ 1364 King

    Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...

随机推荐

  1. CakePHP的文章分类的功能实现

    前些天实现了[微个人.大家园]的文章文类功能.现在回忆一下,是如何完成的吧. 具体的操作步骤如下: 1.在文章posts表里添加一个列,category_id. 2.在数据库中添加一个数据表,cate ...

  2. transition的四个属性

    transition-property 规定设置过渡效果的 CSS 属性的名称. transition-duration 规定完成过渡效果需要多少秒或毫秒. transition-timing-fun ...

  3. 单例模式,多种实现方式JAVA

    转载请注明出处:http://cantellow.iteye.com/blog/838473 第一种(懒汉,线程不安全): public class Singleton { private stati ...

  4. Java开发工程师必会做试题

    一.单选题     (共19道题,每题5分) 1.下面有关java的一些细节问题,描述错误的是? A.构造方法不需要同步化 B.一个子类不可以覆盖掉父类的同步方法 C.定义在接口中的方法默认是publ ...

  5. SQLite 入门教程(四)增删改查,有讲究

    增删改查操作,其中增删改操作被称为数据操作语言 DML,相对来说简单一点. 查操作相对来说复杂一点,涉及到很多子句,所以这篇先讲增删改操作,以例子为主,后面再讲查操作. 一.插入数据 INSERT I ...

  6. MySQL命令行下查看运行状态

    查看MySQL的运行状态用命令行的show语句show status是查看MySQL运行情况,和上面那种通过pma查看到的信息基本类似. show variables是查看MySQL的配置参数,还可以 ...

  7. Java设计模式(学习整理)----装饰模式

    1.概念: (在我看来,模式就像是是一种思想,在这种思想的指引下,对代码和结构的一番加工和整合而已!都是套路!) 装饰模式又称包装(Wrapper)模式,是以对客户端透明的方式扩展对象的功能,是继承关 ...

  8. SGU 167.I-country

    时间限制:0.75s 空间限制:65M 题意: 在一个n*m(n,m<=15)的网格中,每个格子有一个值,现在从网格中取出k(k<=n*m)个,保证在选中的格子中从任意一个格子去另外的所有 ...

  9. SGU 171.Sarov zones

    简单的贪心.优先weight最大的,优先匹配Q值大的地区 code #include <iostream> #include <algorithm> #include < ...

  10. Getopt::Long 模块的简单使用

    用法简介 1.带值参数传入程序内部 ※参数类型:整数, 浮点数, 字串 GetOptions( 'tag=s' => \$tag ); ‘=’表示此参数一定要有参数值, 若改用’:'代替表示参数 ...