POJ 1201 差分约束系统
来源:互联网 发布:索隆 知乎 编辑:程序博客网 时间:2024/04/28 19:43
题目
Intervals
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 24326 Accepted: 9247
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
题意
给出一些区间,从这些区间里挑一些数。要求每个区间里的数不能小于一定的值。问最少要挑多少个数
题解
定义d[i]为在[0,i]区间里挑了d[i]个数
则有约束条件:
d[i+1]>=d[i],后面的数肯定不会比前面的数少。
d[i]+1>=d[i+1],d[i+1]比d[i]最多多一个1.
d[a[i].R] - d[a[i].L]>=a[i].v,满足题意包含合适的数。
然后就可以用Bllman-ford算法计算结果了。
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <stack>#include <string>#include <set>#include <cmath>#include <map>#include <queue>#include <sstream>#include <vector>#include <iomanip>#define m0(a) memset(a,0,sizeof(a))#define mm(a) memset(a,0x3f,sizeof(a))#define m_1(a) memset(a,-1,sizeof(a))#define f(i,a,b) for(i = a;i<=b;i++)#define fi(i,a,b) for(i = a;i>=b;i--)#define lowbit(a) ((a)&(-a))#define FFR freopen("data.in","r",stdin)#define FFW freopen("data.out","w",stdout)#define INF 0x3f3f3f3ftypedef long long ll;typedef long double ld;const ld PI = acos(-1.0);using namespace std;#define SIZE ( 50000+10)struct Edge { int L, R; int v;};Edge a[SIZE];int d[SIZE];int main() { //ios_base::sync_with_stdio(false); cin.tie(0); int n; while (~scanf("%d", &n)) { int i; int Min = INF; int Max = -INF; f(i, 1, n) { int L, R, K; scanf("%d%d%d", &L, &R, &K); L++; R++; Min = min(L - 1, Min); Max = max(R, Max); a[i].L = L - 1; a[i].R = R; a[i].v = K; } m0(d); int ok = 1; while (ok) { ok = 0; f(i, 1, n) { if (d[a[i].L] > d[a[i].R] - a[i].v) { d[a[i].L] = d[a[i].R] - a[i].v; ok = 1; } } f(i, Min, Max - 1) if (d[i] > d[i + 1]) { d[i] = d[i + 1]; ok = 1; } f(i, Min, Max - 1) if (d[i + 1] > d[i] + 1) { d[i + 1] = d[i] + 1; ok = 1; } } printf("%d\n", d[Max] - d[Min]); } return 0;}
- Poj 1201 (差分约束系统)
- POJ 1201 Intervals 差分约束系统
- POJ 1201 Intervals 差分约束系统
- poj 1201 (差分约束系统)
- POJ 1201-Intervals(差分约束系统)
- POJ -- 1201--Intervals (差分约束系统)
- POJ 1201 差分约束系统
- poj 1201 Intervals 差分约束系统
- POJ 1201 Candies [差分约束系统]
- POJ 1201 Intervals [差分约束系统]
- POJ 1201 Intervals 差分约束系统
- POJ 1201 Intervals 差分约束系统
- POJ 1201 Intervals 差分约束系统
- POJ-1201 (差分约束系统)
- 【差分约束系统】POJ 1201--Intervals
- [POJ 1201] Intervals 差分约束系统
- POJ 1201 Intervals 差分约束系统
- 差分约束系统 poj
- xUtils开源库导入AS失败,换成导入xUtils3开源库
- HTML5移动端meta标签中viewpoint简介
- Android 网络请求方法
- [LeetCode]Next Permutation下一个排列问题
- 基于Bootstrap使用jQuery实现输入框组input-group的添加与删除
- POJ 1201 差分约束系统
- 安卓动态调试七种武器之长生剑 - Smali Instrumentation
- Java EE 之Hibernate初步接触 one-to-many
- JSON.stringify的使用
- Lab 3:自行车码表
- PAT-B 1030. 完美数列
- poj 初级训练计划数据结构总结
- Hadoop之自定义输入数据(一)
- 在CSDN的安卓版本的App中找到了的一个BUG