# 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;
}



• 本文已收录于以下专栏：

举报原因： 您举报文章：zoj 1508 | poj 1201 Intervals 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)