图论(差分约束系统):POJ 1201 Intervals
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 24099 | Accepted: 9159 |
Description
Write a program that:
reads the number of intervals, their end points 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.
Input
first line of the input contains an integer n (1 <= n <= 50000) --
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 <= 50000
and 1 <= ci <= bi - ai+1.
Output
output contains exactly one integer equal to the minimal size of set Z
sharing at least ci elements with interval [ai, bi], for each
i=1,2,...,n.
Sample Input
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
Sample Output
6
#include <iostream>
#include <cstdio>
#include <cstring>
#define inf 0x7ffffff
using namespace std;
const int maxn=;
const int maxm=;
int cnt,fir[maxn],to[maxm],val[maxm],nxt[maxm],dis[maxn],vis[maxn];
void addedge(int a,int b,int v)
{
nxt[++cnt]=fir[a];
to[cnt]=b;
val[cnt]=v;
fir[a]=cnt;
}
int q[maxm],front,back;
void Spfa(int S,int T)
{
fill(dis,dis+S+,inf);
q[front=]=S;back=;
vis[S]=;
dis[S]=;
while(front<back)
{
int node=q[front++];vis[node]=false;
for(int i=fir[node];i;i=nxt[i]){
if(dis[to[i]]<=dis[node]+val[i])continue;
dis[to[i]]=dis[node]+val[i];
if(!vis[to[i]])
q[back++]=to[i];
vis[to[i]]=true;
}
}
} int main()
{
int n,maxl=;
while(~scanf("%d",&n)){
memset(fir,,sizeof(fir));
cnt=;maxl=;
for(int i=;i<=n;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
addedge(b,a-,-c);
maxl=max(maxl,b);
}
for(int i=;i<=maxl;i++){
addedge(i-,i,);
addedge(i,i-,);
}
Spfa(maxl,);
printf("%d\n",-dis[]);
}
}
图论(差分约束系统):POJ 1201 Intervals的更多相关文章
- 图论--差分约束--POJ 1201 Intervals
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30971 Accepted: 11990 Descripti ...
- POJ 1201 Intervals(图论-差分约束)
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20779 Accepted: 7863 Descri ...
- poj 1201 Intervals(差分约束)
做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,500 ...
- POJ 1201 Intervals(差分约束 区间约束模版)
关于差分约束详情可阅读:http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html 题意: 给定n个区间[L,R], 每个区间至 ...
- POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...
- poj 1201 Intervals 解题报告
Intervals Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Submit Statu ...
- POJ 1201 Intervals
题意:有n个区间[a,b],每个区间有一个值c.找一个集合中的元素使得每个区间至少有c个元素在这个集合中,问最小的集合大小. 思路:设d[i+1]表示0到i有多少个数在这个集合中,显然对于每个区间,d ...
- zoj 1508 poj 1201 Intervals
差分约束系统. #include<cstdio> #include<cstring> #include<cmath> #include<vector> ...
- 图论--差分约束--POJ 1364 King
Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...
随机推荐
- Oracle中wm_concat()的使用方法
以下两种方式使用wm_concat()的使用方法是等效的. 方法一:使用窗口函数,wm_concat支持窗口函数 select distinct classKey,className, classOr ...
- PowerDesigner15的安装和破解
一.PowerDesigner15的安装 运行安装包,出现如下安装界面
- spring xml 空模板-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- Android 使用弹出对话框,报Unable to add window错误
今天在使用Android弹出对话框的时候,报了一个unable to add window错误,我的代码如下 new AlertDialog.Builder(getApplicationContext ...
- 服务器证书安装配置指南(IIS7.5) 分类: ASP.NET 2014-11-05 12:39 105人阅读 评论(0) 收藏
1.启动IIS管理器,点击开始菜单->所有程序->管理工具->Internet信息服务(IIS)管理器: 2.选择"服务器证书": 3.在右边窗口,选择" ...
- python爬虫scrapy的Selectors参考文档
http://doc.scrapy.org/en/1.0/topics/selectors.html#topics-selectors-htmlcode
- Css3渐变(Gradients)-径向渐变
CSS3径向渐变-radial-gradient()/repeating-radial-gradient() 径向渐变由它的中心定义. 创建径向渐变,至少定义两种颜色节点,呈现平稳过度的颜色.同时,你 ...
- CSS3渐变(Gradients)-线性渐变
CSS3渐变(Gradients)可以让你在两个或多个指定颜色之间显示平稳的过度,包括透明度. 以前,你必须使用图像来实现这些效果.但是,通过Css3渐变(Gradients),你可以减少下载的事件和 ...
- google的西联汇款可以使用工行代收
- Deep Learning 学习随记(七)Convolution and Pooling --卷积和池化
图像大小与参数个数: 前面几章都是针对小图像块处理的,这一章则是针对大图像进行处理的.两者在这的区别还是很明显的,小图像(如8*8,MINIST的28*28)可以采用全连接的方式(即输入层和隐含层直接 ...