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 题目大意: 一些母牛按序号排成一条直线.有两 ...
随机推荐
- Oracle数据库基本语句练习
以ORACLE数据库为主提纲:第一部分.SQL语言基础 第一章:Oracle命令类别及sql简单语法介绍第二章:oracle的基本函数第三章:oracle的数据类型第四章:多表连接技术 第二部分.or ...
- Spark核心组件
Spark核心组件 1.RDD resilient distributed dataset, 弹性分布式数据集.逻辑上的组件,是spark的基本抽象,代表不可变,分区化的元素集合,可以进行并行操作.该 ...
- MySQL入门很简单: 13 数据备份和还原
1. 数据备份 1)使用mysqldump命令备份 第一种:备份一个数据库 mysqldump -u username -p dbname table1 table2 ... > BackupN ...
- 增量数据同步中间件DataLink分享(已开源)
项目介绍 名称: DataLink['deitə liŋk]译意: 数据链路,数据(自动)传输器语言: 纯java开发(JDK1.8+)定位: 满足各种异构数据源之间的实时增量同步,一个分布式.可扩展 ...
- CRUD全栈式编程架构之MVC的扩展设计
MVC执行流程 路由的扩展 我理解的路由作用有以下几个 Seo优化,用“/”分开的url爬虫更爱吃 物理和逻辑文件分离,url不再按照文件路径映射 Controller,Action的选择 MVC路由 ...
- react组件生命周期过程
实例化 首次实例化 getDefaultProps getInitialState componentWillMount render componentDidMount 实例化完成后的更新 getI ...
- MySQL 开机自启动
MySQL 开机自启动 chkconfig add mysqld 或者 echo "/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc ...
- VMware 12安装Mac OS X 10.11
去年写了一篇安装Mac OS X 10.10的文章,看到大家都想体验OS X,大多数都能成功,但也在其中发现了一些问题,所以更新一下,希望对大家有所帮助. 1048VMware 11安装Mac O ...
- Oracle 11g基础
一.打开.关闭数据库 sqlplus "/as sysdba" connect system/manager as sysdba 关闭 shutdown immediate; 打开 ...
- MySQL中的if和case语句使用总结
create table test( id int primary key auto_increment, name ), sex int ) ),(),(),() ,'男','女') from te ...