###### zoj 1508 | poj 1201 Intervals

（1）z集合中范围在[ai, bi]的整数个数即S[bi] - S[ai-1]至少为ci，得到不等式组

S[bi] - S[ai-1] >= ci ，转化为 S[ai-1] - S[bi] <= -ci;

（2）S[i] - S[i - 1] <= 1

（3）S[i] - S[i - 1] >= 0 => S[i - 1] - S[i] <= 0

M = dist[maxb] - dist[minb - 1]

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define FOR(i,a,b) for(i = (a); i < (b); ++i)
#define FORE(i,a,b) for(i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(i = (a); i > (b); --i)
#define FORDE(i,a,b) for(i = (a); i >= (b); --i)
#define CLR(a,b) memset(a,b,sizeof(a))
#define PB(x) push_back(x)

const int MAXN = 50010;
const int MAXM = 50010;
const int hash_size = 25000002;
const int INF = 0x7f7f7f7f;

bool vis[MAXN];
int cnt, n;
int maxb = -1, minb = INF;
struct edge {
int v, w, nxt;
}p[MAXM * 4];

void addedge(int u, int v, int w) {
p[cnt].v = v;
p[cnt].w = w;
}

int spfa(int x) {
int i;

CLR(cnt0, 0);
CLR(vis, false);
FORE(i, minb - 1, maxb)
dist[i] = INF;
dist[x] = 0;
queue<int> q;
q.push(x);
vis[x] = true;
++cnt0[x];
while(!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for(i = head[u]; i != -1; i = p[i].nxt) {
int v = p[i].v;
if(p[i].w + dist[u] < dist[v]) {
dist[v] = p[i].w + dist[u];
if(!vis[v]) {
q.push(v);
vis[v] = true;
}
}
}
}
return dist[minb - 1];
}

void init() {
int i, ai, bi, ci;

while(scanf("%d", &n) != EOF) {
cnt = 0;
maxb = -1, minb = INF;
FORE(i, 1, n) {
scanf("%d %d %d", &ai, &bi, &ci);
maxb = max(maxb, bi);
minb = min(minb, ai);
}
FORE(i, minb, maxb) {
}
printf("%d\n", -spfa(maxb));
}
}

int main() {
init();
return 0;
}



#### POJ 1201 Intervals(差分约束)

2014-07-18 10:17:14

#### POJ1201-Intervals

2011-07-31 17:58:40

#### zoj1508Intervals&poj1201 Intervals【差分约束论文题】

2016-03-02 13:06:01

#### poj1201 - Intervals

2012-09-07 10:22:25

#### zoj 1508 && poj 1201 Intervals

2015-03-11 14:43:49

#### POJ 1201Intervals（差分约束系统）

2017-02-20 08:31:15

#### Poj 1201 Intervals(差分约束)

2017-02-07 08:20:55

#### poj 1201/ZOJ 1508 Intervals 差分约束

2013-05-17 01:13:02

#### POJ 1201 & HDU1384 & ZOJ 1508 Intervals 差分约束

2017-04-12 21:51:25

#### ZOJ-3953-Intervals【贪心】【17th浙大校赛】

2017-04-10 12:22:17

## 不良信息举报

zoj 1508 | poj 1201 Intervals