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. mysqli预处理和事务处理

    1 应用环境 mysqli预处理功能(大量数据处理时使用) 2 步骤 a)mysqli连接数据库 $mysqli = new mysqli('localhost','root','root','chu ...

  2. msg url

  3. 【转】【WPF】资源读取 URI

    一开始看到WPF里面经常用如下语句来构造资源文件Uri: Uri uri = new Uri("/AssemblyName;component/image.png"); 我还以为这 ...

  4. OpenGL 4.3配置教程

    OpenGL 4.3配置教程 下载开发包 需要下载的开发包主要包含如下几个组件:freeglut+glew+ OpenGL.Development.Cookbook+源码+GLM+SOIL. Open ...

  5. VBS基础篇 - 过程(sub 与 Function)

    VBS基础篇 - 过程(sub 与 Function) 在VBscript中,有两种procedure:Sub procedure与Function procedure Sub过程:是包含在 Sub  ...

  6. [CareerCup] 3.2 Min Stack 最小栈

    3.2 How would you design a stack which, in addition to push and pop, also has a function min which r ...

  7. html 空格-有趣的试验

    首先,先给大家看一组demo <input /> <input type="submit" /> 展示效果: 为什么会出现空格呢?input不是行内元素吗? ...

  8. Android空闲教室查询-资料

    这是去年某课程的一个称作“研究型学习”的东西的报告的展示PPT,有点失败的是这个APP的名字起得不太好……PPT上的功能都实现了,其他功能都没有.一年了,程序都忘差不多了,也暂时没有时间分享.就先把P ...

  9. IE firefox 兼容性整理

    1.尽量用jquery操作. 2.jquery取值时要用准确的方法,attr(), val(), text(), html(). 例如: <span value="a"> ...

  10. 微软发布独立Android模拟器 为开发者提供测试

    微软发布了 Visual Studio 2015 正式版,除了免费的社交版之外,另外也有付费的专业版.这套工具除了提供 Windows 应用程序的整合环境之外,你也可以利用它来开发 Android 程 ...