Time Limit: 2000MS
Meamory Limit: 65536K

Total Submissions: 27949
Accepted: 10764

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

Source

Southwestern Europe 2002

【题解】

      ①这是一个差分约束模型。

      ②本题约束条件基于前缀和sum数组。

      ③外加相邻点的前缀和关系(最多相差1)。

#include<queue>
#include<stdio.h>
#include<algorithm>
#define inf 1000000007
#define go(i,a,b) for(int i=a;i<=b;i++)
#define fo(i,a,x) for(int i=a[x],v=e[i].v;i;i=e[i].next,v=e[i].v)
const int N=50010;
using namespace std;
bool inq[N];queue<int>q;
struct E{int v,next,w;}e[N<<1];
int n,a[N],b[N],c[N],head[N],k=1,S=1e9,T,d[N];
void ADD(int u,int v,int w){e[k]=(E){v,head[u],w};head[u]=k++;} void Build()
{
go(i,1,n)scanf("%d %d %d",a+i,b+i,c+i);
go(i,1,n)S=min(S,a[i]-1),T=max(T,b[i]);
go(i,1,n)ADD(a[i]-1,b[i],c[i]);
go(i,S+1,T)ADD(i,i-1,-1);
go(i,S,T-1)ADD(i,i+1,0);
} void SPFA()
{
go(i,S,T)d[i]=-inf;d[S]=0;q.push(S);int u;
while(!q.empty()){inq[u=q.front()]=0;q.pop();fo(i,head,u)
if(d[u]+e[i].w>d[v])d[v]=d[u]+e[i].w,!inq[v]?q.push(v),inq[v]=1:1;}
} int main()
{
scanf("%d",&n);Build();
SPFA();printf("%d\n",d[T]);
return 0;
}//Paul_Guderian

.

【POJ 1201 Intervals】的更多相关文章

  1. 【POJ 1201】 Intervals(差分约束系统)

    [POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: ...

  2. poj 1201 Intervals 解题报告

    Intervals Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Submit Statu ...

  3. POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束

    POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...

  4. 【38.24%】【POJ 1201】Intervals

    Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25902 Accepted: 9905 Description You are ...

  5. 【POJ 1201】 Intervals

    [题目链接] 点击打开链接 [算法] 令sum(n)表示区间[1,n]中选了几个点 那么,显然有以下不等式 : 1. sum(n)- sum(n - 1) >= 0 2. sum(n) -  s ...

  6. POJ 1201 Intervals【差分约束】

    传送门:http://poj.org/problem?id=1201 题意: 有n个如下形式的条件:,表示在区间[, ]内至少要选择个整数点.问你满足以上所有条件,最少需要选多少个点? 思路:第一道差 ...

  7. 【题解】 POJ 1201 Intervals(差分约束)

    懒得复制,戳我戳我 Solution: 这道题就是一个板子题 抽象成第\(a\)至第\(b\)间选择数的个数为\(c\),我们就可以用前缀和来表示,这样就可以得到不等式\(s[b]-s[a-1]> ...

  8. poj 1201 Intervals【差分约束+spfa】

    设s为前缀和,首先显然的条件是\[ s_{bi}-s_{ai-1}>=c \],然后隐含的是\[ s_i-s_{i-1}>=0 s_i-s_{i-1}<=1 \] 然后根据差分约束, ...

  9. poj 1201 Intervals(差分约束)

    题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...

随机推荐

  1. hack游戏攻略(梦之光芒黑客小游戏)

    2019.2.11 继续玩~~还是黑客游戏闯关类的 地址:http://monyer.com/game/game1/ 直接查看页面代码: first.php就是了: 查看源代码: 这里尝试输入 两个空 ...

  2. Vee-validate学习

    Vee-validate使用方法 首先引入 <script src="https://cdn.bootcss.com/vee-validate/2.0.9/vee-validate.j ...

  3. UVA ~ 514 ~ Rails (栈)

    参考:https://blog.csdn.net/ZscDst/article/details/80266639 #include <iostream> #include <cstd ...

  4. Hadoop数据倾斜及解决办法

    数据倾斜:就是大量的相同key被partition分配到一个分区里,map /reduce程序执行时,reduce节点大部分执行完毕,但是有一个或者几个reduce节点运行很慢,导致整个程序的处理时间 ...

  5. 通过py2exe打包python程序的过程中,解决的一系列问题

    py2exe的使用方法参考<py2exe使用方法>. 注:程序可以在解释器中正常运行,一切问题都出在打包过程中. 问题1: 现象:RuntimeError: maximum recursi ...

  6. 护网杯 three hit 复现(is_numeric引发的二次注入)

    1.题目源码 https://github.com/ZhangAiQiang/three-hit 题目并不真的是当时源码,是我根据做法自己写的,虽然代码烂,但是还好能达到复现的目的 ,兄弟们star一 ...

  7. Selenium页面工厂+数据驱动测试框架

    工程的目录结构: pom.xml文件: <?xml version="1.0" encoding="UTF-8"?><project xmln ...

  8. spring-boot分页插件

    1.分页插件,spring-boot.,第一次调用时,存值到 model.addAttribute("status", id);页面获取2.页面获取 后台存入的值,放在input ...

  9. SPOJ 694

    题面 题意: 给一个字符串,求它有多少个不同的子串 多组数据. Solution : 模板题,用所有的减去重复的即可. #include <cstdio> #include <alg ...

  10. Linux服务架设篇--traceroute命令

    作用: 查看数据包在传输过程中经过了哪些IP地址的路由器.网关. 工作原理: 首先向远程主机发送TTL为1的UDP数据包,按照协议规定,路由器收到数据包,TTL值减1,这时TTL就为0,路由器就会丢弃 ...