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 ...
随机推荐
- 赵雅智_android获取本机运营商,手机号部分能获取
手机号码不是全部的都能获取.仅仅是有一部分能够拿到. 这个是因为移动运营商没有把手机号码的数据写入到sim卡中.SIM卡仅仅有唯一的编号.供网络与设备 识别那就是IMSI号码,手机的信号也能够说是通过 ...
- 0x21 剪枝
这一章真是心态崩,剪枝太玄学啦,特别是那个搜索顺序我靠真的... poj1011 枚举答案,搜索记录当前到第几根木棒. 剪枝:1.从大到小排序 2.排除等效,这个感觉还行,就是木棒按大小顺序进去,去除 ...
- 存储概念解析:NAS与SAN的区别
目前存储网络技术领域中的两个主旋律是SAN(存储区域网络)和NAS(网络连接区域存储),两者都宣称是解决现代企业高容量数据存储需求的最佳选择. 正如在餐厅就餐时大厨不会为您传菜,跑堂不会为您烹制鲜橙烩 ...
- Noip前紧急抢救
管他会不会,知道结论就好了 紧急抢救知识 斯特林数 第一类斯特林数 递推公式 \[ S[n][k]=(n-1)\times S[n-1][k]+S[n-1][k-1] \] 处理的问题是将n个数划分为 ...
- 基础apache命令
在启动Apache服务之前,可以使用下面的命令来检查配置文件的正确性. C:\Apache2.2\bin> httpd -n Apache2.2 -t 还可以通过命令行控制Apache服务 ...
- VB.net 捕获项目全局异常
在项目中添加如下代码:新建窗口来显示异常信息. Namespace My '全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 '添加后还需要一个From用来显示 ...
- 含神经网络的离线AI翻译 APP
功能特性 下载 https://www.microsoft.com/en-us/store/p/translator/9wzdncrfj3pg
- 安装Oracle 12c及解决遇到的问题
一.[INS-30131]执行安装程序验证所需的初始设置失败(原因:无法访问临时位置) 原文链接:https://blog.csdn.net/u013388049/article/details/85 ...
- Pyhton学习——Day40
#一个完整的 JavaScript 实现是由以下 3 个不同部分组成的:# 核心(ECMAScript)# 文档对象模型(DOM) Document object model (整合js,css,ht ...
- laravel报错:Unable to detect application namespace.
使用报错:Unable to detect application namespace. 是conposer.json格式不对