Intervals

Time Limit: 2000MS Memory Limit: 65536K

Total Submissions: 30971 Accepted: 11990

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<cstring>
#include<cstdio>
using namespace std;
#define inf 99999
#define maxx 50005
struct edge
{
int u,v,w;
}edge[maxx];
int n;
int dist[maxx];
int l;//左端点的最小值
int r;//右端点的最大值 void bellman_ford()
{
int flag=1,t;
while(flag)
{
flag=0;
for(int i=1;i<=n;i++)
{
t=dist[edge[i].u]+edge[i].w;
if(dist[edge[i].v]>t)
{
dist[edge[i].v]=t;
flag=1;
}
}
for(int i=r;i>l;i--)
{
t=dist[i-1]+1;
if(dist[i]>t)
{
dist[i]=t;flag=1;
}
}
for(int i=r;i>l;i--)
{
t=dist[i];
if(dist[i-1]>t)
{
dist[i-1]=t;
flag=1;
}
}
}
} int main()
{
scanf("%d",&n);
r=1,l=inf;
int a,b,c;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
edge[i].u=b,edge[i].v=a-1,edge[i].w=-c;
if(a<l) l=a;
if(b>r) r=b;
dist[i]=0;
}
bellman_ford();
printf("%d\n",dist[r]-dist[l-1]);
return 0;
}

图论--差分约束--POJ 1201 Intervals的更多相关文章

  1. 图论--差分约束--POJ 3159 Candies

    Language:Default Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 43021   Accep ...

  2. 图论--差分约束--POJ 3169 Layout(超级源汇建图)

    Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 < ...

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

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

  4. 图论--差分约束--POJ 2983--Is the Information Reliable?

    Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...

  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. POJ 1201 Intervals【差分约束】

    传送门:http://poj.org/problem?id=1201 题意: 有n个如下形式的条件:,表示在区间[, ]内至少要选择个整数点.问你满足以上所有条件,最少需要选多少个点? 思路:第一道差 ...

  8. poj 1201 Intervals(差分约束)

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

  9. POJ 1201 Intervals (经典) (差分约束)

    <题目链接> 题目大意:给你$n$段区间,$a_i,b_i,c_i$ 表示在 $[a_i,b_i]$ 区间内至少要选择$c_i$个点.现在问你在满足这n个条件的情况下,最少要选多少个点? ...

随机推荐

  1. JAVA中使用Date和SimpleDateFromat类表示时间

    转自:https://www.imooc.com/code/2335 仅做个人学习保存之用,侵删! 在程序开发中,经常需要处理日期和时间的相关数据,此时我们可以使用 java.util 包中的 Dat ...

  2. 29.2 Iterator 迭代器ConcurrentModificationException:并发修改异常处理

    /** Iterator:迭代器* * 需求:判断集合中是否包含元素java,如果有则添加元素android * Exception in thread "main" java.u ...

  3. Struts2-学习笔记系列(13)-类型转换异常和校验器

    Struts2框架有默认的类型转换错误拦截机制,该配置在struts-default.xml中,名叫conversionError,但是想使用需要继承ActionSupport. 默认的错误提示信息是 ...

  4. pgsql的使用

    Deepin上面pgsql的启动 service postgresql start 停止 service postgresql stop 查看pgsql的版本 psql --version

  5. Docker php安装扩展步骤详解

    前言 此篇,主要是演示docker-php-source , docker-php-ext-install ,docker-php-enable-docker-configure 这四个命令到底是用来 ...

  6. 第八节:time和random模块

    定义: 模块是一组Python代码的集合,可以使用其他模块,也可以被其他模块使用. 重点: 1.模块的名字不要和自带的模块名字相同,不然会优先调用自己的那个模块,因为查找模块的时候是按照sys.pat ...

  7. Linux/UNIX 下 “command not found” 原因分析及解决

    在使用 Linux/UNIX 时,会经常遇到 "command not found" 的错误,就如提示的信息,Linux /UNIX 没有找到该命令.原因无外乎你命令拼写错误或 L ...

  8. C - Ivan the Fool and the Probability Theory---div2

    题目连接:https://codeforces.com/contest/1248/problem/C 思路: 注意上下两排的关系,如果说上面那一排有两个方格连续,那么他相邻的两排必定和他相反,如果说当 ...

  9. JMeter分布式压测-常见问题之( Cannot start. localhost.localdomain is a loopback address)

    问题描述: JMeter分布式测试时,以Linux系统作为被测服务器,在其中启动 jmeter-server 服务时出现异常,系统提示如下: [root@localhost bin]# ./jmete ...

  10. 4. Object

    1. Object.is( );  //用来判断,不同等 == 与===接近.NaN作出的调整 let obj={a:1,b:2}; Object.is(obj,obj);//true Object. ...