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 ...
随机推荐
- Linux(Centos)中tcpdump参数用法详解(转)
在linux下进行编程开发的人尤其是网络编程的人会经常需要分析数据包,那么一定会用到tcpdump,下面就是关于tcpdump的使用方法说明(1). tcpdump的选项 -a 将网络地址 ...
- Vc6.0打开该文件坠毁
这是一个微软bug,下面是用户给出的溶液: http://blog.163.com/wjatnx@yeah/blog/static/12758622820138110530322/ http://bl ...
- 连接字符串中Min Pool Size的理解是错误,超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
Min Pool Size的理解是错误的 假设我们在一个ASP.NET应用程序的连接字符串中将Min Pool Size设置为30: <add name="cnblogs" ...
- 【Android进阶】判断网络连接状态并自动界面跳转
用于判断软件打开时的网络连接状态,若无网络连接,提醒用户跳转到设置界面 /** * 设置在onStart()方法里面,可以在界面每次获得焦点的时候都进行检测 */ @Override protecte ...
- Storm基础知识
上一篇文章我们介绍一个简单的Storm起源,今天我去学习Storm一些主要的知识,他的基本使用基本的了解.幸运的是,,不是太困难,假设我们理解Hadoop的MapReduce模型的话.看这个也是很类似 ...
- struts2于validate要使用
package com.test.action; import com.opensymphony.xwork2.ActionSupport; import com.test.model.User; p ...
- HTML5 CSS3 精美案例 : 达到VCD盒个性幻灯片
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/31015121 哈,首先感谢下w3cfuns教师,行~ 行.这一次分享发夹CSS3 ...
- 第十六章——处理锁、阻塞和死锁(3)——使用SQLServer Profiler侦测死锁
原文:第十六章--处理锁.阻塞和死锁(3)--使用SQLServer Profiler侦测死锁 前言: 作为DBA,可能经常会遇到有同事或者客户反映经常发生死锁,影响了系统的使用.此时,你需要尽快侦测 ...
- Java操作memcached(一)
Memcached事实上,两次Hash算法 第一次hash算法被用于定位Memcached示例 第二次hash算法是底部HashMap中间hash算法 Hash算法 1.依据余数 ...
- SQL Server 连接问题-命名管道
原文:SQL Server 连接问题-命名管道 出自:http://blogs.msdn.com/b/apgcdsd/archive/2011/01/12/sql-server-1.aspx 一.前言 ...