Description

You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. 
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

The first line of the input contains an integer n (1 <= n <= 50000) -- the number of intervals. The following n lines describe the intervals. The (i+1)-th line of the input contains three integers ai, bi and ci separated by single spaces and such that 0 <= ai <= bi <= 50000 and 1 <= ci <= bi - ai+1.

Output

The output contains exactly one integer equal to the minimal size of set Z sharing at least ci elements with interval [ai, bi], for each i=1,2,...,n.

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的更多相关文章

  1. POJ1201 Intervals[差分约束系统]

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26028   Accepted: 9952 Descri ...

  2. POJ1201 Intervals差分约束系统(最短路)

    Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...

  3. POJ1201 Intervals(差分约束)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 10966 Description You ...

  4. POJ1201 Intervals 【差分约束】

    题目链接 POJ1201 题解 差分约束 令\(a[i]\)表示是否选择\(i\),\(s[i]\)表示\(a[i]\)的前缀和 对\(s[i] \quad i \in [-1,50000]\)分别建 ...

  5. POJ1201 Intervals【差分约束系统】

    Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...

  6. POJ1201 Intervals (差分约束)

    You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...

  7. POJ1201 Intervals(差分约束系统)

    与ZOJ2770一个建模方式,前缀和当作点. 对于每个区间[a,b]有这么个条件,Sa-Sb-1>=c,然后我就那样连边WA了好几次. 后来偷看数据才想到这题还有两个隐藏的约束条件. 这题前缀和 ...

  8. poj1201 Intervals【差分约束+SPFA】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303365.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

  9. 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 ...

随机推荐

  1. 用uGUI开发自定义Toggle Slider控件

    一.前言 写完<Unity4.6新UI系统初探>后,我模仿手机上的UI分别用uGui和NGUI做了一个仅用作演示的ToggleSlider,我认为这个小小的控件已能体现自定义控件的开发过程 ...

  2. 工厂模式(Factory Patter)

    1.工厂模式简介 工厂模式属于创建型模式,是专门用来创建对象的模式,抽象了实例化的过程.工厂模式分为 : 工厂方法模式.抽象工厂模式. 在学习工厂方法模式.抽象工厂之前,首先先要了解一下简单工厂模式, ...

  3. [原创]Gerrit中文乱码问题解决方案分享

    应开发同事的要求,部署了Gitlab+Gerrit+Jenkins的持续集成环境. 但是发现了一个问题,Gerrit登陆后有中文乱码出现. 具体情况如下: (1)Git代码中的中文乱码处理: 为妥善解 ...

  4. MVC权限验证之ActionFilterAttribute

    参考:http://www.cnblogs.com/waitingfor/archive/2011/12/27/2303784.html ActionFilterAttribute是Action过滤类 ...

  5. Groovy Spock环境的安装

    听说spock是一个加强版的Junit,今天特地安装了,再把过程给大家分享一下. 首先说明,我的Java项目是用maven管理的. 我用的Eclipse是Kelper,开普勒. 要使用Spock之前, ...

  6. android.hardware.Camera类及其标准接口介绍

    android.hardware.Camera类及其标准接口介绍,API level 19 http://developer.android.com/reference/android/hardwar ...

  7. C语言 文件操作6--文件打开方式详解

    fopen文件打开模式 r代表read的简写,+代表可读可写,w代表write,b代表bit二进制位,t代表text r 打开只读文件,该文件必须存在r+ 打开可读可写的文件,该文件必须存在(这里的写 ...

  8. Sublime 将 Tab 转为空格

    最近在使用 vue-cli 搭建项目,但每次用 Hbuilder 编写 vue 文件的时候,如果存在<script>部分就会报错,错误信息大意是说空格有问题.仔细研究了之后才知道,这是因为 ...

  9. 我所知道的HttpContext.Current

    在MVC中,HttpContext.Current是比较常见的对象,可以用它来进行Session,Cache等的保存等.但是它并不是无处不在的,下面就慢慢来揭开它的面纱. 当我们向服务端发送请求的时候 ...

  10. python数字图像处理(1):环境安装与配置

    一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...