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. 第二百零四天 how can i 坚持

    我应该不会看错吧.最近媒体热炒小米衰落了,有必要那么大张旗鼓的报道吗?小米.华为,坚决看好小米.感觉华为品牌有些杂乱,在走三星的老路,小米有些苹果的影子,但是,多了个互联网.互联网... 未来孰优孰劣 ...

  2. Servlet 2.4 规范之第一篇:概览

          写在前面的话: 本系列是对<Java Servlet Specification Version 2.4>的完全翻译,力争但不保证完美表达出英文原文的思想内涵.如有疏漏之处,还 ...

  3. ProxyFactory的一个问题

    今天写了一段很简单的代码,但一直都有问题.代码如下. 接口定义 using System; using System.Collections.Generic; using System.Linq; u ...

  4. sql的union用法

    sql中union是很常见的,尤其是创建视图时,完全离不开union. SQL UNION 操作符合并两个或多个 SELECT 语句的结果,UNION 内部的每个 SELECT 语句必须拥有相同数量的 ...

  5. LabVIEW数据记录和存储—XML文件

    XML(eXtensible Markup Language)是一种目前广泛使用的数据传输和存储的格式,其本质上是一种文本文件,可以使用任何一个文本编辑工具打开和修改.类似于HTML,XML被设计为具 ...

  6. 转载php在IIS中运行

    在IIS中配置PHP运行环境简单步骤 安装 IIS 7.0 打开 Control Panel\Programs\Programs and Features\Turn Windows features ...

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

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

  8. 你真的会玩SQL吗?实用函数方汇总

    http://www.cnblogs.com/zhangs1986/p/4917800.html 实用函数方法 由于有些知识很少被用到,但真需要用时却忘记了又焦头烂额的到处找. 现在将这些‘冷门“却有 ...

  9. 关于以DataTable形式批量写入数据的案例

    void IDataAccess.CommandDataTable(DataTable dt, string ProcedureName, System.Data.Common.DbParameter ...

  10. Ceph Jewel 10.2.3 环境部署

    Ceph 测试环境部署 本文档内容概要 测试环境ceph集群部署规划 测试环境ceph集群部署过程及块设备使用流程 mon节点扩容及osd节点扩容方法 常见问题及解决方法 由于暂时没有用到对象存储,所 ...