POJ1201-Intervals(差动限制)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 20786 | Accepted: 7866 |
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
ai <= bi <= 50000 and 1 <= ci <= bi - ai+1.
Output
Sample Input
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
Sample Output
6
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
using namespace std;
const int maxn = 50000+10000;
const int INF = 1e9;
int n;
int src,sink;
bool inQue[maxn];
int dist[maxn];
queue<int>que;
struct edge{
int to,next,w;
edge(int to,int next,int w):to(to),next(next),w(w){}
};
int head[maxn];
vector<edge> e; void addedge(int from,int to,int w){
e.push_back(edge(to,head[from],w));
head[from] = e.size()-1;
}
void spfa(){
for(int i = src; i <= sink; i++){
inQue[i] = 0;
dist[i] = INF;
}
inQue[sink] = 1;
que.push(sink);
dist[sink] = 0;
while(!que.empty()){
int u = que.front();
que.pop();
inQue[u] = 0;
for(int i = head[u]; i != -1; i = e[i].next){
if(dist[e[i].to] > dist[u]+e[i].w){
dist[e[i].to] = dist[u]+e[i].w;
if(!inQue[e[i].to]){
inQue[e[i].to] = 1;
que.push(e[i].to);
}
}
}
} }
int main(){ int m;
freopen("in","r",stdin);
while(~scanf("%d",&m)){
e.clear();
src = maxn,sink = -1;
memset(head,-1,sizeof head);
while(m--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
++b;
src = min(src,a);
sink = max(sink,b);
addedge(b,a,-c);
}
for(int i = src; i < sink; i++){
addedge(i+1,i,0);
addedge(i,i+1,1);
}
spfa();
cout<<-dist[src]<<endl; }
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ1201-Intervals(差动限制)的更多相关文章
- POJ1201 Intervals[差分约束系统]
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26028 Accepted: 9952 Descri ...
- POJ1201 Intervals差分约束系统(最短路)
Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...
- POJ1201 Intervals
Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- POJ1201 Intervals 【差分约束】
题目链接 POJ1201 题解 差分约束 令\(a[i]\)表示是否选择\(i\),\(s[i]\)表示\(a[i]\)的前缀和 对\(s[i] \quad i \in [-1,50000]\)分别建 ...
- POJ1201 Intervals【差分约束系统】
Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...
- POJ1201 Intervals (差分约束)
You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...
- POJ1201 Intervals(差分约束系统)
与ZOJ2770一个建模方式,前缀和当作点. 对于每个区间[a,b]有这么个条件,Sa-Sb-1>=c,然后我就那样连边WA了好几次. 后来偷看数据才想到这题还有两个隐藏的约束条件. 这题前缀和 ...
- poj1201 Intervals【差分约束+SPFA】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303365.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
- POJ 1201 && HDU 1384 Intervals(差动制动系统)
职务地址:POJ 1201 HDU 1384 依据题目意思.能够列出不等式例如以下: Sj-Si>=c; Si-S(i-1)>=0; S(i-1)-Si>=-1; 然后用最短路s ...
随机推荐
- YT新人之巅峰大决战04
Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Ed ...
- 图表引擎AChartEngine 一
MainActivity.java package com.example.achartengine0; import org.achartengine.ChartFactory; import or ...
- 经验19--C#大事
以前学过C#大事.但我还没有搞懂怎么弄. 这一次,他们下进行了研究. 1.定义参数类,对于参数的传递活动.(可以省略) public class UserEventArgs { ...
- 3、采用Gradle创Libgdx工程
(原文链接:http://www.libgdx.cn/topic/20/3-%E4%BD%BF%E7%94%A8gradle%E5%88%9B%E5%BB%BAlibgdx%E9%A1%B9%E7%9 ...
- JavaScipt面向对象编程----闭包
在javascript中闭包是一个非常不好理解的概念,可是确实一个不可逃避的东西,那么今天我们就来一起学习一下闭包. 什么是闭包? 闭包:官方"的解释是:闭包是一个拥有很多变量和绑定了这些变 ...
- RESTful架构详解(转)
1. 什么是REST REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. 它首次出现在2000年Roy Fielding的 ...
- html 块状元素 行内元素 内联元素
块状(Block)类型的元素的width默认为100%,而行内(Inline)类型的元素则是根据自身的内容及子元素来决定宽度. 块元素(block element) address - 地址 bloc ...
- hdu 3683 Gomoku (模拟、搜索)
Gomoku Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- top使用命令
top命令 第一行和uptime命令一样,都有系统的负载. 10:36:19 当前时间 up 1day .7min 系统执行时间.格式为天 时:分 1 user 当前登录用户数 load averag ...
- java反思reflect 分析Object物
直接看它的一个例子 </pre><pre name="code" class="java">package reflect; impor ...