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. HDU 1242 Rescue (BFS(广度优先搜索))

    Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  2. 判断时间大小 yyyy-MM-dd 格式

    // yyyy-MM-dd function bigThanToday(someDate){ var date = new Date(); var dateStr = date.getFullYear ...

  3. JPBM4.4基础及数据库说明

    JPBM4.4基础及数据库说明 对jBPM4.4数据库的几张表简单介绍: A.资源库和运行时表结构 JBPM4_DEPLOYMENT   流程定义表                           ...

  4. OC: 类的扩展、类的延展、协议、 NSDate

      NSDateFormatter 指定⽇日期格式: NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter ...

  5. 【转】获取手机的ipv4地址

    http://blog.csdn.net/yueqinglkong/article/details/17391051 直接贴代码: public class GetLocalIpAddress ext ...

  6. Hadoop on Mac with IntelliJ IDEA - 8 单表关联NullPointerException

    简化陆喜恒. Hadoop实战(第2版)5.4单表关联的代码时遇到空指向异常,经分析是逻辑问题,在此做个记录. 环境:Mac OS X 10.9.5, IntelliJ IDEA 13.1.5, Ha ...

  7. 根据PID和VID得到USB转串口的串口号

    /******************************************************************************* * * FindAppUART.cpp ...

  8. go exec: "gcc": executable file not found in %PATH%

    win下使用go,在进行go run build.go时,提示 exec: "gcc": executable file not found in %PATH% 原因是sqlitl ...

  9. Looksery Cup 2015 H. Degenerate Matrix 数学

    H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...

  10. Android自己主动化測试解决方式

    如今,已经有大量的Android自己主动化測试架构或工具可供我们使用,当中包含:Activity Instrumentation, MonkeyRunner, Robotium, 以及Robolect ...