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. 快速记忆JavaScript中exec和match的使用

    JS模式匹配中exec,match用得非常多,所以掌握其用法对我们进行字符串的处理帮助非常大 1.exec的定义其用法        exec与match主要的不同是,exec是正则表达式里面的方法. ...

  2. 服务器证书安装配置指南(IIS7.5) 分类: ASP.NET 2014-11-05 12:39 105人阅读 评论(0) 收藏

    1.启动IIS管理器,点击开始菜单->所有程序->管理工具->Internet信息服务(IIS)管理器: 2.选择"服务器证书": 3.在右边窗口,选择" ...

  3. 在iframe中获取iframe外的对象

    parent.document.getElementById("dom ID"); $($(parent.document.getElementById("video-i ...

  4. 利用linq快速判断给定数字是否包含在某个段范围内

    一.需求: 知道某段范围0x0020~0x007F0x00A0~0x017F0x01A0~0x01CF0x01F0~0x01FF0x0210~0x021F0x1EA0~0x1EFF给定一个值,快速判断 ...

  5. NSArray 跟 NSMutableArray 使用 区别

    NSArray 可变数组 一.NSArray是静态数组,创建后数组内容及长度不能再修改. 实例: //用arrayWithObjects初始化一个不可变的数组对象. //初始化的值之间使用逗号分开,以 ...

  6. JS键盘码值表

    值得注意的是,keypress事件中获取的keycode.which,都是按键对应的ascii值,而不完全对应下面的列表. 将字符转换为ascii值可以用charCodeAt函数. keycode 8 ...

  7. windows编程中 一些前缀区分 IDR和IDD

    IDC_:控件的ID命名前缀(Control) IDM_:菜单的ID命名前缀(Menu) IDD_:对话框的ID命名前缀(Dialog) IDR_:资源的ID命名前缀(Resource) IDS_:字 ...

  8. C#遍历所有的Textbox控件并赋值为String.Empty

    foreach (Control control in this.Controls) { if (control.GetType().Name.Equals("TextBox")) ...

  9. ie8 background css没有显示?——都是空格惹的祸

    ie8 background css没有显示?——都是空格惹的祸

  10. WWDC2014之iOS使用动态库

    苹果的开放态度 WWDC2014上发布的Xcode6 beta版有了不少更新,其中令我惊讶的一个是苹果在iOS上开放了动态库,在Xcode6 Beta版的更新文档中是这样描述的: Frameworks ...