poj 1201 Interval (查分约束)
/*
数组开大保平安.
查分约束:
输入的时候维护st和end
设每个点取元素di个 维护元素个数前缀和s
Sbi-Sai-1>=ci
即:建立一条从ai-1到bi的边 权值为ci 表示ai到bi的最小取元素个数
然后跑st到end的最长路 (建边就已经保证了最优)
最后 dis[end] 即为end的前缀和 即为st到end 符合每一个约束的最小去元素值
同时查分约束也满足性质 Sai-Sai-1>=0 Sai-1-Sai>=-1
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define maxn 500010
using namespace std;
int m,num,st=maxn,end,head[maxn],dis[maxn],f[maxn];
struct node
{
int v,t,pre;
}e[maxn];
int init()
{
int x=;char s;s=getchar();
while(s<''||s>'')s=getchar();
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x;
}
void Add(int from,int to,int dis)
{
num++;
e[num].v=to;
e[num].t=dis;
e[num].pre=head[from];
head[from]=num;
}
void SPFA()
{
queue<int>q;
q.push(st);
f[st]=;
dis[st]=;
while(!q.empty())
{
int k=q.front();
q.pop();
f[k]=;
for(int i=head[k];i;i=e[i].pre)
if(dis[e[i].v]<dis[k]+e[i].t)
{
dis[e[i].v]=dis[k]+e[i].t;
if(f[e[i].v]==)
{
q.push(e[i].v);
f[e[i].v]=;
}
}
}
}
int main()
{
m=init();
int x,y,z;
for(int i=;i<=m;i++)
{
x=init();y=init();z=init();
Add(x,y+,z);
st=min(st,x);end=max(end,y+);
}
for(int i=st;i<=end;i++)
{
Add(i,i+,);
Add(i+,i,-);
}
memset(dis,-,sizeof(dis));
SPFA();
printf("%d\n",dis[end]);
return ;
}
poj 1201 Interval (查分约束)的更多相关文章
- 洛谷P1993 小 K 的农场(查分约束)
/* 加深一下对查分约束的理解 建图的时候为了保证所有点联通 虚拟一个点 它与所有点相连 权值为0 然后跑SPFA判负环 这题好像要写dfs的SPFA 要不超时 比较懒 改了改重复进队的条件~ */ ...
- codevs 1242 布局(查分约束+SPFA)
/* 查分约束. 给出的约束既有>= 又有<= 这时统一化成一种 Sb-Sa>=x 建边 a到b 权值为x Sb-Sa<=y => Sa-Sb>=-y 建边 b到a ...
- poj 1364 查分约束
#include<stdio.h> #include<iostream> #include<stack> #include<string.h> usin ...
- Integer Intervals POJ - 1716_查分约束_
Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; co ...
- POJ 1201 Intervals【差分约束】
传送门:http://poj.org/problem?id=1201 题意: 有n个如下形式的条件:,表示在区间[, ]内至少要选择个整数点.问你满足以上所有条件,最少需要选多少个点? 思路:第一道差 ...
- poj 1201 Intervals(差分约束)
做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,500 ...
- BZOJ2330 糖果题解 查分约束
BZOJ 2330 糖果题解 差分约束系统 + SPFA 题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2330 Description ...
- POJ 1201 Intervals (差分约束,最短路)
题意: 有一个集合Z,其元素都是整整数,但是数量未知.现有n个约束,形如 [a,b]=c 表示整数区间[a,b]中有c个元素在Z中出现.问集合Z最小可能含多少个元素? 思路: 对于所给的区间 cnt[ ...
- POJ 1201 Intervals (经典) (差分约束)
<题目链接> 题目大意:给你$n$段区间,$a_i,b_i,c_i$ 表示在 $[a_i,b_i]$ 区间内至少要选择$c_i$个点.现在问你在满足这n个条件的情况下,最少要选多少个点? ...
随机推荐
- [Usaco2006 Dec]Milk Patterns
[Usaco2006 Dec]Milk Patterns Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天 产奶的质量,但连续的若干天的 ...
- 实现一个简单的sniffer
#include<stdio.h> #include<pcap.h> #include<unistd.h> #include<stdlib.h> //# ...
- 转:关于PHP性能优化
原文来自于:http://www.cnblogs.com/qq78292959/archive/2012/12/28/2837272.html 1.升级硬件的一般规则:对于 PHP 脚本而言,主要的瓶 ...
- PHP调试工具Xdebug安装配置教程
说道PHP代码调试,对于有经验的PHPer,通过echo.print_r.var_dump函数,或PHP开发工具zend studio.editplus可解决大部分问题,但是对于PHP入门学习的童鞋来 ...
- 转:aptitude 命令详解
原文:http://www.isspy.com/aptitude-%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3/ aptitude aptitude 是 Debian GN ...
- Arctic Network
poj2349:http://poj.org/problem?id=2349 题意:有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.告诉你卫星电台的个数S,让你求最 ...
- cf E. George and Cards
http://codeforces.com/contest/387/problem/E 题意:给你n个数,然后在输入k个数,这k个数都在n个数中出现,进行每一次操作就是在n个数中选择长度为w的连续序列 ...
- 【HDOJ】2444 The Accomodation of Students
图论的题目.着色原理+二分图匹配. #include <cstdio> #include <cstring> #define MAXN 205 char map[MAXN][M ...
- mt7601 driver
http://download.csdn.net/detail/u011500307/7011649 http://my.oschina.net/fgq611/blog/180750 http://b ...
- Implement Trie (Prefix Tree) ——LeetCode
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...