hdoj--1384--Intervals(差分约束)
Intervals
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
and such that 0 <= ai <= bi <= 50 000 and 1 <= ci <= bi - ai + 1.
Process to the end of file.
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
6
#include<stdio.h>
#include<string.h>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f
int head[100100],vis[1000100],n,cnt;
int dis[100100];
int l,r;
struct node
{
int u,v,val;
int next;
}edge[1001000];
void init()
{
cnt=0;
memset(head,-1,sizeof(head));
l=INF;
r=-1;
}
void add(int u,int v,int val)
{
node E={u,v,val,head[u]};
edge[cnt]=E;
head[u]=cnt++;
}
void getmap()
{
int a,b,c;
for(int i=0;i<n;i++)
{
cin>>a>>b>>c;
l=min(a,l);
r=max(r,b);
add(b,a-1,-c);
}
for(int i=l;i<=r;i++)
{
add(i,i-1,0);
add(i-1,i,1);
}
}
void SPFA()
{
for(int i=l-1;i<=r;i++)
dis[i]=i==r?0:INF;
memset(vis,0,sizeof(vis));
queue<int>q;
q.push(r);
vis[r]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=0;
for(int i=head[u];i!=-1;i=edge[i].next)
{
node E=edge[i];
if(dis[E.v]>dis[E.u]+edge[i].val)
{
dis[E.v]=dis[E.u]+edge[i].val;
if(!vis[E.v])
{
vis[E.v]=1;
q.push(E.v);
}
}
}
}
cout<<-dis[l-1]<<endl;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
init();
getmap();
SPFA();
}
return 0;
}
hdoj--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,建立 一条 ...
- hdoj 1384 Intervals
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- 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 1201 Intervals(差分约束)
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...
- poj 1201 Intervals——差分约束裸题
题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...
- poj1201 Intervals——差分约束
题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...
- Hdu 1384(差分约束)
题目链接 Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- Codeforces Round #316 (Div. 2)E. Pig and Palindromes DP
E. Pig and Palindromes Peppa the Pig was walking and walked into the forest. What a strange coinci ...
- UVA 10127- Ones 数学
Given any integer 0 ≤ n ≤ 10000 not divisibleby 2 or 5, some multiple of n is a number whichin decim ...
- elasticsearch如何安全重启节点
elasticsearch如何安全重启节点 标签: elasticsearch 节点 | 发表时间:2016-05-24 03:58 | 作者:kfcman 分享到: 出处:http://www.it ...
- 循环神经网络(RNN, Recurrent Neural Networks)介绍
原文地址: http://blog.csdn.net/heyongluoyao8/article/details/48636251# 循环神经网络(RNN, Recurrent Neural Netw ...
- DB-MySQL:MySQL 复制表
ylbtech-DB-MySQL:MySQL 复制表 1.返回顶部 1. MySQL 复制表 如果我们需要完全的复制MySQL的数据表,包括表的结构,索引,默认值等. 如果仅仅使用CREATE TA ...
- [Tomcat]Tomcat安全设置
1.关闭服务器端口:server.xml默认有下面一行: <Server port="8005" shutdown="SHUTDOWN"> 这样允许 ...
- 理解z-index和css中的层叠顺序问题(大神技术博的读后感?)
一直对 z-index不太理解,今天看到了大神的博客...http://www.zhangxinxu.com/wordpress/tag/z-index/ 1.层叠上下文:是一个名词!是一个性质!此时 ...
- Hessian 接口使用示例总结
一.使用hessian接口准备 首先,hessian接口的使用,必须要准备hessian接口的jar包,本文使用的jar包如下:hessian-4.0.7.jar; Hessian接口的使用一般是在两 ...
- 密信(Mesince)首创全自动邮件加密,颠覆传统邮件加密软件
电子邮件泄密已经成为一个全球性的日益严峻的安全问题,解决这个问题的唯一有效办法就是电子邮件内容先加密后发送.然而,使用基于S/MIME标准的传统邮件加密软件进行邮件加密,需要用户具备一定的技术基础.用 ...
- web 安全主题