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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ struct node {
int u, v, w;
int nxt;
}edge[maxn];
int head[maxn];
int tot;
int dis[maxn];
bool vis[maxn];
void addedge(int u, int v, int w) {
edge[++tot].u = u; edge[tot].v = v; edge[tot].w = w;
edge[tot].nxt = head[u]; head[u] = tot;
}
void spfa() {
queue<int>q;
q.push(0);
vis[0] = 1; dis[0] = 0;
while (!q.empty()) {
int u = q.front(); q.pop(); vis[u] = 0;
for (int i = head[u]; i; i = edge[i].nxt) {
int v = edge[i].v;
if (dis[v] < dis[u] + edge[i].w) {
dis[v] = dis[u] + edge[i].w;
if (!vis[v]) {
q.push(v); vis[v] = 1;
}
}
}
}
} int main() {
//ios::sync_with_stdio(0);
// int T; rdint(T);
// while (T--) {
ms(head); memset(dis, -0x3f, sizeof(dis));
ms(vis); tot = 0;
int maxx = 0; int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int a, b, c; rdint(a); rdint(b); rdint(c);
addedge(a, b + 1, c); maxx = max(maxx, b + 1);
}
for (int i = 1; i <= maxx; i++) {
addedge(i, i - 1, -1); addedge(i - 1, i, 0);
}
spfa();
cout << dis[maxx] << endl;
// if (T)cout << endl;
// }
return 0;
}

Intervals POJ - 1201 差分约束的更多相关文章

  1. poj 1201 差分约束

    http://www.cnblogs.com/wangfang20/p/3196858.html 题意: 求集合Z中至少要包含多少个元素才能是每个区间[ai,bi]中的元素与Z中的元素重合个数为ci. ...

  2. POJ 1201 差分约束+SPFA

    思路: 差分约束,难在建图.(我是不会告诉你我刚学会SPFA的...) 把每个区间的ai–>bi连一条长度为ci的边. k–>k+1连一条长度为0的边. k+1–>k连一条长度为-1 ...

  3. POJ 1201 差分约束(集合最小元素个数)

    题意:       给你一个集合,然后有如下输入,a ,b ,c表示在范围[a,b]里面有至少有c个元素,最后问你整个集合最少多少个元素. 思路:       和HDU1384一模一样,首先这个题目可 ...

  4. Intervals poj 1201 差分约束系统

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22503   Accepted: 8506 Descri ...

  5. POJ 1384 Intervals (区间差分约束,根据不等式建图,然后跑spfa)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others ...

  6. poj 3159(差分约束经典题)

    题目链接:http://poj.org/problem?id=3159思路:题目意思很简单,都与给定的条件dist[b]-dist[a]<=c,求dist[n]-dist[1]的最大值,显然这是 ...

  7. poj Layout 差分约束+SPFA

    题目链接:http://poj.org/problem?id=3169 很好的差分约束入门题目,自己刚看时学呢 代码: #include<iostream> #include<cst ...

  8. POJ - 3169 差分约束

    题意:n头牛,按照编号从左到右排列,两头牛可能在一起,接着有一些关系表示第a头牛与第b头牛相隔最多与最少的距离,最后求出第一头牛与最后一头牛的最大距离是多少,如         果最大距离无限大则输出 ...

  9. POJ 1201 Intervals(图论-差分约束)

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20779   Accepted: 7863 Descri ...

随机推荐

  1. ajax stream 一边下载二进制数据一边处理

    最近有在做 stream 下载,并且边下载 stream 边处理功能.解析二进制的功能.最初参考了 flv.js 的 flv stream 下载处理功能,发现他并没有使用的 XMLHttpReques ...

  2. git内部原理-第一篇

    本人计划写一些关于<git内部原理>的文章 计划每周一篇

  3. ATL和vc++中的智能指针(分别是CComPtr和_com_ptr_t)

    一.智能指针的概念 智能指针是一个类,不是指针,智能指针在所包含的指针不再被使用时候会自动释放该所包含指针所占用的系统资源,而不用手动释放. 原理:智能指针封装了包含指针的AddRef()函数和Rel ...

  4. linux命令学习笔记(22):find 命令的参数详解

    find一些常用参数的一些常用实例和一些具体用法和注意事项. .使用name选项: 文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用. 可以使用某种文件名 模式来匹配文 ...

  5. android sqlite,大数据处理、同时读写

    1. 批量写入,采用事物方式,先缓存数据,再批量写入数据,极大提高了速度 288条,直接inset  into  耗时7秒 8640条,     批量写入  耗时5-7秒 try { this.myD ...

  6. 发布django 程序

    1.配置需求环境 pip freeze > requirements.txt 在开发环境将工程依赖的包导出. pip install virtualenv pip install virtual ...

  7. Linux 下网卡参数配置

    目录 Linux 下网卡参数配置 第一种:修改 interfaces 文件 网卡配置实例 回环参数配置 DHCP方式配置 静态 IP 地址分配 无线网卡配置 March 17, 2015 7:48 P ...

  8. 11g RAC 如何备份OCR,利用备份恢复OCR,ocrdump

    OCR备份 OCR的备份有2种方式,自动备份和手工备份. 自动备份策略: Oracle Clusterware 每隔4小时,CRSD 进程会自动对OCR 进行一次备份,在任意时刻,oracle 总会保 ...

  9. git导入项目

    远程仓库已经存在,使用的是gitblit,作为终端eclipse如何从中拷贝代码呢? 0.准备工作,windows->preference->team->git->config ...

  10. 人物-IT-马云:马云

    ylbtech-人物-IT-马云:马云 马云 (阿里巴巴集团创始人) 马云,男,汉族,中共党员,1964年9月10日生于浙江省杭州市,祖籍浙江省嵊州市谷来镇, 阿里巴巴集团主要创始人,现担任阿里巴巴集 ...