POJ 1201 Intervals
2016-08-02 22:09
316 查看
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.
【题目分析】
同poj1716一模一样,直接复制AC
【代码】
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.
【题目分析】
同poj1716一模一样,直接复制AC
【代码】
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> #define inf 0x3f3f3f3f using namespace std; int h[400001],fr[400001],ne[400001],to[400001],w[400001],en=0,d[400001]; int inq[400001]; int n,m,maxx; inline void add(int a,int b,int c) {to[en]=b;ne[en]=h[a];fr[en]=a;w[en]=c;h[a]=en++;} inline void bfs() { for (int i=0;i<=maxx;++i) d[i]=-inf; queue<int>q; q.push(0); inq[0]=1;d[0]=0; while (!q.empty()) { int x=q.front();q.pop(); inq[x]=0; for (int i=h[x];i>=0;i=ne[i]) { if (d[x]+w[i]>d[to[i]]) { d[to[i]]=d[x]+w[i]; if (!inq[to[i]]) { q.push(to[i]); inq[to[i]]=1; } } } } cout<<d[maxx]<<endl; } int main() { cin>>n; maxx=-1; memset(h,-1,sizeof h); for (int i=1;i<=n;++i) { int a,b,c; cin>>a>>b>>c; add(a,b+1,c); maxx=max(maxx,b+1); } for (int i=0;i<maxx;++i) { add(i,i+1,0); add(i+1,i,-1); } bfs(); }
相关文章推荐
- poj 1201 Intervals 差分约束
- 【POJ 1201】 Intervals(差分约束系统)
- POJ 1201-Intervals(差分约束系统)
- poj 1201 Intervals( spfa + 差分约束)
- POJ 1201 Intervals <差分约束系统 + SPFA / 贪心 + 树状数组>
- poj 1201 Intervals(最短路+spfa+差分约束系统)
- POJ 1201 Intervals(图论-差分约束)
- [POJ 1201] Intervals 差分约束系统
- POJ 1201 Intervals
- *POJ 1201 - Intervals(查分约束)
- POJ 1201/hdu 1384 Intervals【差分约束+SPFA】
- POJ 1201 Intervals(差分约束)
- poj 1201 Intervals(差分约束系统)
- POJ 1201 Intervals (区间差分约束)
- POJ1201-Intervals(差分约束)
- POJ 1201 Intervals (差分约束系统, 贪心+线段树)
- poj 1201 Intervals
- POJ 1201 Intervals 差分约束+spfa
- POJ 1201 & HDU1384 & ZOJ 1508 Intervals(差分约束+spfa 求最长路径)
- poj 1201 Intervals 解题报告