HDU 1384 Intervals(差分约束)
Intervals
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4292 Accepted Submission(s):
1624
n integers c1, ..., cn.
Write a program that:
> reads the
number of intervals, their endpoints 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
<= n <= 50 000) - 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 <= 50 000 and
1 <= ci <= bi - ai + 1.
Process to the end of file.
minimal size of set Z sharing at least ci elements with interval [ai, bi], for
each i = 1, 2, ..., n.
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define MAXN 50100
using namespace std; struct Edge{
int to,nxt,w;
}e[MAXN<<];
int dis[MAXN],head[MAXN];
bool vis[MAXN];
int cnt,n,l,r;
queue<int>q; void init()
{
memset(head,,sizeof(head));
cnt = ;
l = ;
r = ;
}
void add(int u,int v,int w)
{
++cnt;
e[cnt].w = w;
e[cnt].to = v;
e[cnt].nxt = head[u];
head[u] = cnt;
}
void spfa()
{
memset(dis,0x3f,sizeof(dis));
memset(vis,false,sizeof(vis));
q.push(r);
vis[r] = true;
dis[r] = ;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i=head[u]; i; i=e[i].nxt)
{
int v = e[i].to;
int w = e[i].w;
if (dis[v]>dis[u]+w)
{
dis[v] = dis[u]+w;
if (!vis[v])
{
vis[v] = true;
q.push(v);
}
}
}
vis[u] = false ;
}
printf("%d\n",-dis[l-]);
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
init()
for (int a,b,c,i=; i<=n; ++i)
{
scanf("%d%d%d",&a,&b,&c);
l = min(l,a);
r = max(r,b);
add(b,a-,-c); //b-(a-1)>=c
}
for (int i=l; i<=r; ++i)
{
add(i,i-,); //i-(i-1)>=0
add(i-,i,); //i-(i-1)<=1
}
spfa();
}
return ;
}
HDU 1384 Intervals(差分约束)的更多相关文章
- hdu 1384 Intervals (差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1384 Intervals (差分约束)
/* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...
- Hdu 1384(差分约束)
题目链接 Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1384 Intervals (差分约束)
Problem - 1384 好歹用了一天,也算是看懂了差分约束的原理,做出第一条查分约束了. 题意是告诉你一些区间中最少有多少元素,最少需要多少个元素才能满足所有要求. 构图的方法是,(a)-> ...
- HDU 1384 Intervals【差分约束-SPFA】
类型:给出一些形如a−b<=k的不等式(或a−b>=k或a−b<k或a−b>k等),问是否有解[是否有负环]或求差的极值[最短/长路径].例子:b−a<=k1,c−b&l ...
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- POJ 1364 / HDU 3666 【差分约束-SPFA】
POJ 1364 题解:最短路式子:d[v]<=d[u]+w 式子1:sum[a+b+1]−sum[a]>c — sum[a]<=sum[a+b+1]−c−1 ...
- poj 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- zoj 1508 Intervals (差分约束)
Intervals Time Limit: 10 Seconds Memory Limit: 32768 KB You are given n closed, integer interva ...
- POJ 3169 Layout (HDU 3592) 差分约束
http://poj.org/problem?id=3169 http://acm.hdu.edu.cn/showproblem.php?pid=3592 题目大意: 一些母牛按序号排成一条直线.有两 ...
随机推荐
- iis 部署网站常见问题
环境IIS6.0,win2003server 首先打开iis,左边菜单选中”Web服务扩展“,讲Active Server Pages 和 ASP.NET v2.0.50727设置为允许 1.创建网站 ...
- WebRTC协议
webrtc协议介绍 MDN webrtc协议 ICE 交互式连接建立Interactive Connectivity Establishment (ICE) 是一个允许你的浏览器和对端浏览器建立连接 ...
- Java Map应用
一.基本API使用方法 直接上代码,注释讲解 package com.map; import java.util.HashMap; import java.util.Iterator; import ...
- Linux MySQL单实例源码编译安装5.6
cmake软件 tar -zxvf cmake-2.8.11.2.tar.gz cd cmake-2.8.11.2 ./bootstrap make make install cd ../ 依赖包 ...
- nginx缓存批量清除
研究了一段时间的缓存清除,说说了解的三种方式吧. 1. 原始的只增加缓存模块的,根据访问的路径一条条清除. 根据此方式要进行批量清除的话,必须在设定的缓存目录下通过自己写的程序来读取ng ...
- python selenium 下拉框
下拉框的处理如下代码: 定位select有很多种方式,这里介绍两种定位方式 1.二次定位 先定位到下拉框:self.dr.find_element_by_css_selector('#business ...
- 问题 D: C++ 习题 输出日期时间--友元函数
题目描述 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函数中调用dis ...
- layui table 用法
1.使用模板列 改变样式 获取嵌套数据{ field: '', width: '12%', title: '响应状态', sort: true, templet: function (d) { if ...
- MySQL游标(cursor) 定义及使用
概念 游标(Cursor)它使用户可逐行访问由SQL Server返回的结果集. 使用游标(cursor)的一个主要的原因就是把集合操作转换成单个记录处理方式. 用SQL语言从数据库中检索数据后,结果 ...
- prepareStatament和Statement和callableStatement的区别
关系与区别 Statement.PreparedStatement和CallableStatement都是接口(interface) Statement 1.Statement接口提供了执行语句和获取 ...