POJ 1201 Intervals (差分约束)
2012-10-05 20:56
393 查看
题意:n个区间。每个区间[ai,bi] 间有至少有ci 个数。问这些区间至少有多少个数。。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> using namespace std; const int N = 50009; const int M = N<<2; int dist ; struct LT{ int nex,to,dis; } L[M]; int F ,cnt; void add(int f,int t,int d) { L[cnt].dis = d; L[cnt].nex = F[f]; L[cnt].to = t; F[f] =cnt++; } queue<int>que; bool visit ; int spfa(int st,int en) { que.push(st); visit[st] = true; memset(dist,-1,sizeof(dist)); dist[st] = 0; while(!que.empty()){ int e = que.front();que.pop(); visit[e] = false; for(int i=F[e];i;i=L[i].nex){ int to = L[i].to; if(dist[to]<dist[e]+L[i].dis){ dist[to] = dist[e]+L[i].dis; if(!visit[to]) que.push(to),visit[to] = true; } } } return dist[en]; } int main() { freopen("in.txt","r",stdin); int n,r=-1; int a,b,c; scanf("%d",&n);cnt = 1; for(int i=0;i<n;i++) { scanf("%d%d%d",&a,&b,&c); if(a>b) a^=b^=a; add(a,b+1,c);r = max(r,b+1); } add(0,1,0); for(int i=1;i<r;i++) add(i,i+1,0),add(i,i-1,-1); printf("%d\n",spfa(0,r)); return 0; }
相关文章推荐
- poj 1201 Intervals(差分约束,最长路)
- poj 1201 intervals 我的第一个差分约束
- poj 1201 Intervals(差分约束)
- poj 1201 Intervals(差分约束)
- poj 1201 Intervals(差分约束)
- [POJ] 1201 Intervals [差分约束]
- POJ1201 Intervals 【差分约束】
- POJ 1201 Intervals (差分约束)
- POJ 1201 Intervals(差分约束)
- POJ 1201 Intervals【差分约束】
- POJ 1201 Intervals(图论-差分约束)
- POJ 1201 Intervals(差分约束)
- poj 1201 Intervals [差分约束]
- poj 1201 Intervals(差分约束)
- [差分约束]POJ 1201——Intervals
- HDU 1384 && POJ 1201--Intervals 【基础差分约束】
- poj 1201 Intervals(差分约束)
- POJ 1201 Intervals(差分约束)
- poj 1201 Intervals [差分约束]
- POJ训练计划1201_Intervals(差分约束)