POJ1201 区间
题目大意:
给定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 区间的更多相关文章
- 贪心算法----区间选点问题(POJ1201)
题目: 题目的大致意思是,给定n个闭区间,并且这个闭区间上的点都是整数,现在要求你使用最少的点来覆盖这些区间并且每个区间的覆盖的点的数量满足输入的要求点覆盖区间的数量. 输入: 第一行输入n,代表n个 ...
- 【poj1201】 Intervals
http://poj.org/problem?id=1201 (题目链接) 题意 给出n个区间${[ai,bi]}$,要求选出尽可能少的数,使得每个区间i中至少存在${c[i]}$个数. Soluti ...
- ASP.NET Core应用针对静态文件请求的处理[2]: 条件请求与区间请求
通过调用ApplicationBuilder的扩展方法UseStaticFiles注册的StaticFileMiddleware中间件帮助我们处理针对文件的请求.对于StaticFileMiddlew ...
- SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等
在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...
- codevs 1082 线段树练习 3(区间维护)
codevs 1082 线段树练习 3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...
- codevs 1082 线段树区间求和
codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...
- [LeetCode] Find Right Interval 找右区间
Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...
- [LeetCode] Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
随机推荐
- Oracle学习系列4
Oracle学习系列4 ************************************************************************************ 数据库 ...
- SCRUM项目 5.0
5.0--------------------------------------------------- 1.团队成员完成自己认领的任务. 2.燃尽图:理解.设计并画出本次Sprint的燃尽图的理 ...
- sip_hangup_disposition
sip_hangup_disposition This variable contains the value of who sent the SIP BYE message. Some exampl ...
- jQuery的attr与prop,attribute和property区别
jQuery1.6中新添加了一个prop方法,看起来和用起来都和attr方法一样,这两个方法有什么区别呢?这要从HTMl 的attribute与property区别说起,attr与prop正是这两个东 ...
- Type Project has no default.properties file! Edit the project properties to set one.
Description Resource Path Location Type Project has no default.properties file! Edit the project pro ...
- Openstack Neutron OVS ARP Responder
ARP – Why do we need it? In any environment, be it the physical data-center, your home, or a virtual ...
- Parquet文件结构笔记
Parquet是面向分析型业务的列式存储格式,由Twitter和Cloudera合作开发,2015年5月从Apache的孵化器里毕业成为Apache顶级项目,那么这里就总结下Parquet数据结构到底 ...
- 移动端line-height失效
移动端高度过小,使用rem布局时div里面的文字不能用line-height垂直居中: 解决方案,先高度,字体大小扩大n倍,然后利用transform:scale(0.n)缩小即可.
- 在Spring的bean中注入HttpServletRequest解密
我们可以在Spring的bean中轻松的注入HttpServletRequest,使用@Autowired HttpServletRequest request;就可以了. 但是,为什么我们可以直接这 ...
- linux 安装软件程序
1.用aptitude管理软件包 查看已安装的/未安装的等软件包 无法通过aptitude看到一个细节是所有跟某个特定软件包关联的所有文件的列表.利用dpkg命令能看到这个列表. dpkg -L pa ...