题目大意:

给定n个整数区间[ai,bi]和n个整数ci,求一个最小集合Z,满足|Z∩[ai,bi]|>=ci(Z里边在闭区间[ai,bi]的个数不小于ci)。

多组数据:

n(1<=n<=50000)区间的个数

n行:

ai bi ci(0<=ai<=bi<=50000,1<=ci<=bi-ai+1)

_____________________________________________________

这是一道查分约束题目。

Si为0-i中包含在Z中的个数,固有:

Si-Si-1<=1

Si-Si-1>=0

Sbi-Sai-1>=ci

依照上面不等式,变形并建边。

求的Smax-S0>=x,变形为S0-Smax<=-x,所以求max到0的最短路,就是答案的相反数。

_____________________________________________________

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
int n,maxd;
struct edge
{
int u,v,w,next;
}e[];
int head[],js=;
int dis[];
bool inq[];
int inqt[];
queue<int>q;
void init()
{
js=;
maxd=;
memset(head,,sizeof(head));
}
void addage(int u,int v,int w)
{
e[++js].u=u;e[js].v=v;e[js].w=w;
e[js].next=head[u];head[u]=js;
}
bool spfa()
{
memset(inq,,sizeof(inq));
memset(dis,0x7f,sizeof(dis));
memset(inqt,,sizeof(inqt));
q.push(maxd+);
inq[maxd+]=;
inqt[maxd+]=;
dis[maxd+]=;
while(!q.empty())
{
int u=q.front();
q.pop();
inq[u]=;
for(int i=head[u];i;i=e[i].next)
{
int v=e[i].v;
if(dis[v]>dis[u]+e[i].w)
{
dis[v]=dis[u]+e[i].w;
if(!inq[v])
{
inq[v]=;
inqt[v]++;
q.push(v);
if(inqt[v]>)return ;
}
}
}
}
return ;
}
int main()
{
while(scanf("%d",&n)==)
{
init();
for(int a,b,c,i=;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(b>maxd)maxd=b;
addage(b+,a,-c);
} for(int i=;i<=maxd+;i++)
{
addage(i-,i,);
addage(i,i-,);
}
if(spfa())printf("%d\n",-dis[]);
}
return ;
}

POJ1201 区间的更多相关文章

  1. 贪心算法----区间选点问题(POJ1201)

    题目: 题目的大致意思是,给定n个闭区间,并且这个闭区间上的点都是整数,现在要求你使用最少的点来覆盖这些区间并且每个区间的覆盖的点的数量满足输入的要求点覆盖区间的数量. 输入: 第一行输入n,代表n个 ...

  2. 【poj1201】 Intervals

    http://poj.org/problem?id=1201 (题目链接) 题意 给出n个区间${[ai,bi]}$,要求选出尽可能少的数,使得每个区间i中至少存在${c[i]}$个数. Soluti ...

  3. ASP.NET Core应用针对静态文件请求的处理[2]: 条件请求与区间请求

    通过调用ApplicationBuilder的扩展方法UseStaticFiles注册的StaticFileMiddleware中间件帮助我们处理针对文件的请求.对于StaticFileMiddlew ...

  4. SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等

    在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...

  5. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  6. codevs 1082 线段树区间求和

    codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...

  7. [LeetCode] Find Right Interval 找右区间

    Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...

  8. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  9. [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

随机推荐

  1. 排序算法总结(三)选择排序【Select Sort】

    一.原理 选择排序的原理非常简单,就是选出最小(大)的数放在第一位,在剩下的数中,选出最小(大)的数,放在第二位......重复上述步骤,直到最后一个数. 二.过程 原始数据 第一次排序,选出最小的数 ...

  2. Streaming replication slots in PostgreSQL 9.4

    Streaming replication slots are a pending feature in PostgreSQL 9.4, as part of the logical changese ...

  3. pt-online-schema-change 实例

    pt-pmp (http://www.cnblogs.com/ivictor/p/6012183.html) pt-online-schema-change (http://blog.csdn.net ...

  4. IOS开发-属性动画和关键帧动画的使用

    CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...

  5. SilverlightERP&CRM源码(可用于开发基于Silverlight的CRM,OA,HR,进销存等)

    SilverlightERP系统源代码(支持创建OA.SilverlightCRM.HR.进销存.财务等系统之用) 可用于开发以下系统 SilverlightERP SilverlightCRM Si ...

  6. [驱动]内核添加USB转串口驱动支持

    转自:http://blog.csdn.net/gatieme/article/details/49491325 目录 1. 问题 2. 驱动源码 3. 内核配置 4. 编译内核和模块驱动 5. 加载 ...

  7. 原生+jquery 实现好看滚动条。

    //原生 <!doctype html> <html> <head> <meta charset="utf-8"> <titl ...

  8. 【巩固】CSS3的animation基础

    终于结束了最后css3的一节课,关于animation的使用,其实之前已经用过一次.大致要了解的就是,关于如何让动画停在最后一帧的方法.视频里有提到过css3出了个新的样式可以实现,但是老师没有记住, ...

  9. UML精粹2 - 开发过程

    迭代和瀑布过程 两者的本质区别是,你如何将一个项目分解为更小块. 瀑布风格基于活动来分解项目.为了构建软件,你不得不做某些活动:需求分析.设计.编码和测试.为期一年的项目可能有2个月的分析阶段,然后是 ...

  10. css学习笔记(6)

    +++++++++++++++++ CSS HACK+++++++++++++++++IE6.0 能识别 _background:#ff00ff; *background:#ff00ff; +back ...