POJ1201 Intervals
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
Output
Sample Input
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
Sample Output
6
Source
正解:SPFA+差分约束系统
解题报告:
大致题意是给定一些要求,比如说,1到7之间至少有5个数,然后条件需要全部满足,问
这几天刷了几道差分约束系统+SPFA的题目,现在向总给的题目清单里面就只剩下一道半平面交没做了。夏令营回来有时间再切了吧。
这道题也没什么好说的,只不过是根据大于号建图,跑最长路就可以了。
唯一要注意的是因为是前缀和建图,需要把这个序列依次连边,比如说1连2连3这么一直连接下去。
//It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#ifdef WIN32
#define OT "%I64d"
#else
#define OT "%lld"
#endif
using namespace std;
typedef long long LL;
const int inf = (<<);
const int MAXN = ;
const int MAXM = ;
int n;
int first[MAXN],next[MAXM],to[MAXM],w[MAXM];
int dis[MAXN];
bool pd[MAXN];
int ecnt;
int Min,Max;
int ans;
queue<int>Q; inline int getint()
{
int w=,q=;
char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} inline void Init(){
ecnt=; memset(first,,sizeof(first));
Max=; Min=inf;
while(!Q.empty()) Q.pop();
ans=;
} inline void link(int x,int y,int z){
next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; w[ecnt]=z;
} inline void spfa(){
for(int i=;i<=n;i++) dis[i]=-inf;
Q.push(Min); pd[Min]=; dis[Min]=;
while(!Q.empty()) {
int u=Q.front(); Q.pop(); pd[u]=;
for(int i=first[u];i;i=next[i]) { //最长路
int v=to[i];
if(dis[v]<dis[u]+w[i]) {
dis[v]=dis[u]+w[i];
if(!pd[v]){
Q.push(v); pd[v]=;
}
}
}
}
ans=dis[Max];
} inline void solve(){
while(scanf("%d",&n)!=EOF){
Init();
int x,y,z;
for(int i=;i<=n;i++) {
x=getint()-;y=getint();z=getint();
link(x,y,z);
Min=min(Min,x); Max=max(Max,y);
}
for(int i=Min;i<Max;i++){//以前缀和为结点
link(i+,i,-); link(i,i+,);//要使所有点满足s[i+1]-s[i] <= 1 && s[i]-s[i+1] <= 0
}
spfa();
printf("%d",ans);
}
} int main()
{
solve();
return ;
}
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(差分约束)
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 ...
- POJ1201:Intervals(差分约束)
差分约束经典题.设s[i]为前缀和,则有 s[i]-s[i-1]<=1 (i往i-1连-1的边) s[i]>=s[i-1] (i-1往i连0的边) s[b]-s[a-1]>=c (a ...
随机推荐
- Apache Shiro权限框架在SpringMVC+Hibernate中的应用
在做网站开发中,用户权限必须要考虑的,权限这个东西很重要,它规定了用户在使用中能进行哪 些操作,和不能进行哪些操作:我们完全可以使用过滤器来进行权限的操作,但是有了权限框架之后,使用起来会非常的方便, ...
- Asp.net mvc项目架构分享系列之架构搭建初步
copy to:http://www.cnblogs.com/ben121011/p/5014795.html 项目架构各部分解析 Core Models IDAL MSSQLDAL IBLL BLL ...
- UIVisualEffectView为视图添加特殊效果
在iOS 8后,苹果开放了不少创建特效的接口,其中就包括创建毛玻璃(blur)的接口. 通常要想创建一个特殊效果(如blur效果),可以创建一个UIVisualEffectView视图对象,这个对象提 ...
- 【Asp.Net】Asp.Net CommandName作用
数据绑定控件的模板中 CommandName 属性以下属性值会触发特定的事件: Cancel(取消) Delete(删除) Select(选择) Edit(编辑) Insert(插入) Update( ...
- [Elixir007] on_definition规范函数定义时的各种潜规则
1.需求 写一个基于memcache的cache模块, 需要在key前面加上特定的前缀, 所以user cache的原始的store函数应该写成 # user.exdef store(user_id, ...
- Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- CentOS 7 添加win7启动项——修改默认启动项
CentOS 7使用grub2引导启动,在win7之后装完CentOS再启动会丢失win7启动项. 首先,添加win7启动项,步骤如下: 1.使用root登陆系统 2.用文本编辑器打开 /boot/g ...
- 神奇的main方法详解
main函数的详解: public : 公共的. 权限是最大,在任何情况下都可以访问. 原因: 为了保证让jvm在任何情况下都可以访问到main方法. static: 静态 ...
- WebSocket使用教程 2
WebSocket使用教程 - 带完整实例 收藏 james_laughing 发表于 2年前 阅读 46438 收藏 23 点赞 5 评论 4 摘要: WebSocket使用教程 - 带完整实例 什 ...
- Linux常用指令---工作
查看所有用户cat /etc/passwd 复制整个目录cp -ri A/B/* A1/B1/ 若复制过程中询问是否覆盖,输入y按回车 另外若A A1不在同一目录下,最好填绝对路径,就是/xxx/xx ...