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. django、celery异步发邮件

    django.celery异步发邮件 django自带的send_mail发邮件功能执行发邮件功能会因为网络的原因造成花费的时间过长,为了解决这个问题,可以用celery + redis代替 安装包: ...

  2. 细数Java项目中用过的配置文件(YAML篇)

    灵魂拷问:YAML,在项目中用过没?它与 properties 文件啥区别? 目前 SpringBoot.SpringCloud.Docker 等各大项目.各大组件,在使用过程中几乎都能看到 YAML ...

  3. MTK Android 设置下添加一级菜单[ZedielPcbTest]

    功能描述:Android7.1.2 设置下添加一级菜单[ZedielPcbTest],点击ZedielPcbTest,启动ZedielPcbTest.apk应用. 编译:需要在out目录删除Settt ...

  4. javascript入门 之 bind()

    <!DOCTYPE html> <HTML> <HEAD> <meta http-equiv="content-type" content ...

  5. json格式的文件操作

    1.字典转换为字符串(json.dumps) jsongeshi={"name":"yajuan","age":"10" ...

  6. C++值多态:传统多态与类型擦除之间

    引言 我有一个显示屏模块: 模块上有一个128*64的单色显示屏,一个单片机(B)控制它显示的内容.单片机的I²C总线通过四边上的排针排母连接到其他单片机(A)上,A给B发送指令,B绘图. B可以向屏 ...

  7. CH5E07 划分大理石(背包dp+二进制拆分)

    传送门     大意: 有价值分别为1..6的大理石各a[1..6]块,现要将它们分成两部分,使得两部分价值之和相等,问是否可以实现.其中大理石的总数不超过20000. 解题思路: 妥妥的多重背包+二 ...

  8. Docker 清理命令 删除所有的镜像和容器

    杀死所有正在运行的容器 docker kill $(docker ps -a -q) 删除所有已经停止的容器 docker rm $(docker ps -a -q) 删除所有未打 dangling ...

  9. ST表(求解静态RMQ问题)

    例题:https://www.acwing.com/problem/content/1272/ ST表类似于dp. 定义st[i][j]表示以i为起点,长度位2^j的一段区间,即[ i , i + 2 ...

  10. SpringBoot 集成 Elasticsearch

    前面在 ubuntu 完成安装 elasticsearch,现在我们SpringBoot将集成elasticsearch. 1.创建SpringBoot项目 我们这边直接引入NoSql中Spring ...