Intervals
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 22503   Accepted: 8506

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

 
设   s[i]表示集合中小于等于i的元素个数,  u   v   w      s[v]-s[u-1]>=w;
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
using namespace std;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; struct edge
{
int u,v,w;
}edges[*MS]; int maxv,minv;
int dis[MS];
int esize,n; bool bellman()
{
memset(dis,,sizeof(dis));
bool flag=true;
int cnt=;
while(flag)
{
flag=false; //表示没有更新了 if(cnt++>n) //更新次数大于n-1,
return false;
for(int i=;i<esize;i++)
{
if(dis[edges[i].u]+edges[i].w<dis[edges[i].v])
{
dis[edges[i].v]=dis[edges[i].u]+edges[i].w;
flag=true;
}
} //0<=s[i]-s[i-1]<=1 这些边可以不用存储 // i-1 -->i 1 for(int i=minv;i<=maxv;i++)
{
if(dis[i-]+<dis[i])
{
dis[i]=dis[i-]+;
flag=true;
}
} // i--> i-1 0 for(int i=maxv;i>=minv;i--)
{
if(dis[i]<dis[i-])
{
dis[i-]=dis[i];
flag=true;
}
}
}
return true;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
int u,v,w;
esize=;
maxv=;
minv=INF;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&u,&v,&w);
// s[i]表示集合中小于等于i的元素个数
//s[v]-s[u-1]>=w; v->u-1 -w;
edges[esize].u=v;
edges[esize].v=u-;
edges[esize++].w=-w;
if(v>maxv)
maxv=v;
if(u<minv)
minv=u;
}
bellman();
printf("%d\n",dis[maxv]-dis[minv-]);
}
return ;
}
 
 

Intervals poj 1201 差分约束系统的更多相关文章

  1. Intervals POJ - 1201 差分约束

    You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...

  2. poj 1201 差分约束

    http://www.cnblogs.com/wangfang20/p/3196858.html 题意: 求集合Z中至少要包含多少个元素才能是每个区间[ai,bi]中的元素与Z中的元素重合个数为ci. ...

  3. POJ 1201 差分约束+SPFA

    思路: 差分约束,难在建图.(我是不会告诉你我刚学会SPFA的...) 把每个区间的ai–>bi连一条长度为ci的边. k–>k+1连一条长度为0的边. k+1–>k连一条长度为-1 ...

  4. POJ 1201 差分约束(集合最小元素个数)

    题意:       给你一个集合,然后有如下输入,a ,b ,c表示在范围[a,b]里面有至少有c个元素,最后问你整个集合最少多少个元素. 思路:       和HDU1384一模一样,首先这个题目可 ...

  5. 【POJ 1201】 Intervals(差分约束系统)

    [POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: ...

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

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

  7. poj 1201 Intervals(差分约束)

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

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

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

  9. poj 1201 Intervals——差分约束裸题

    题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...

随机推荐

  1. Django 1.6 最佳实践: django项目的服务器自动化部署(转)

    原文:http://www.weiguda.com/blog/41/ 当我们设置服务器时, 不应该每次都使用ssh登录服务器, 再按照记忆一步一步的配置. 因为这样实在是太容易忘记某些步骤了. 服务器 ...

  2. mysql创建用户两次授权

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'     ->     IDENTIFIED BY 'some_pass' ...

  3. AutoCAD DxfCode组码值说明

    值 说明 -5 APP:永久反应器链 -4 APP:条件运算符(仅与 ssget 一起使用) -3 APP:扩展数据 (XDATA) 标记(固定) -2 APP:图元名参照(固定) -1 APP:图元 ...

  4. Python流程控制语句(Control Flow)

    Python用于流程控制的语句包括if,for,while,这些都是从C语言借鉴过来的,然后我们会提到pass语句. 1,if if的语法很简答,我们举一个例子就好,注意关键字if, elif, el ...

  5. 转载sublime text注册码

    直接输入注册码就可以了 ----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 ...

  6. Function.caller

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/caller 非标准 ...

  7. (剑指Offer)面试题17:合并两个排序的链表

    题目: 输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然时按照递增排序的. 链表结点定义如下: struct ListNode{ int val; ListNode* next; }; 思 ...

  8. 组合View Controller时遇到的一点问题

    View Controller的组合应用其实很常见了,比如说Tab bar controller和Navigation view controller的组合使用,像这种一般都是Navigation v ...

  9. Extjs随笔

    { columnWidth : .1, layout : 'form', items : [{ fieldLabel : "至", labelSeparator:'', label ...

  10. SAE J1708 DS36277 MAX3444, DS75176B

    http://en.wikipedia.org/wiki/J1708 J1708 SAE J1708 is a standard used for serial communications betw ...