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 ...
随机推荐
- 真人动作捕捉系统 for Unity
真人动作捕捉 在Asset Store中浏览Mecanim相关的资源时,发现了这个 资源信息 Asset Store:https://www.assetstore.unity3d.com/#/cont ...
- java 21 - 4 字符流的文件复制操作以及简化
既然字节流可以复制文件,那么字符流当然也有. 同样的思路: 数据源: a.txt -- 读取数据 -- 字符转换流 -- InputStreamReader目的地: b.txt -- 写出数据 -- ...
- 使用CSS3画出一个叮当猫
刚学习了这个案例,然后觉得比较好玩,就练习了一下.然后发现其实也不难,如果你经常使用PS或者Flash的话,应该就会知道画个叮当猫是很容易的事,至少我是这么觉得.但是,用CSS3画出来确实是第一次接触 ...
- 【快报】基于K2 BPM的新一代协同办公门户实践交流会
2014年2月28日,“基于BPM的新一代协同办公门户”用户实践交流活动在深圳金茂JW万豪酒店3楼Meet Room IV举办.本次会议由K2携手微软共同举办,邀请到的参会企业都是K2 的BPM老客户 ...
- Docker / CI / CD
CI Weekly #6 | 再谈 Docker / CI / CD 实践经验 CI Weekly 围绕『 软件工程效率提升』 进行一系列技术内容分享,包括国内外持续集成.持续交付,持续部署.自动 ...
- Spring Batch实践
Spring Batch在大型企业中的最佳实践 在大型企业中,由于业务复杂.数据量大.数据格式不同.数据交互格式繁杂,并非所有的操作都能通过交互界面进行处理.而有一些操作需要定期读取大批量的数据,然后 ...
- [py]chr ord
http://www.xuebuyuan.com/2067536.html 也可以help(ord)
- IIS增加并发数
网站出现这样的错误信息:Error Summary: HTTP Error 503.2 - Service UnavailableThe serverRuntime@appConcurrentRequ ...
- JavaScript系列:《JavaScript高级程序设计》,chapter2, 在html中使用JavaScript
2.1.2 延迟脚本 指的是defer属性,且只适用于外部脚本,也就是有defer属性的脚本. 由于各种延迟浏览器对延迟脚本的支持不统一,且在html5之后也不再支持defer属性,所 ...
- js之数组,对象,类数组对象
许久不写了,实在是不知道写点什么,正好最近有个同事问了个问题,关于数组,对象和类数组的,仔细说起来都是基础,其实都没什么好讲的,不过看到还是有很多朋友有些迷糊,这里就简单对于定义以及一下相同点,不同点 ...