题意:给定n个区间[Li,Ri]以及n个整数vi. 现在要有一个集合,使得这个集合和任意[Li,Ri]都有 至少 vi个元素相同. 问这个集合最少要几个元素.

定义S(x) 表示[1,x]中选择的元素的个数. 那么就有S(Ri)−S(Li−1)>=vi

同时还有一个隐形的条件

0<=S(i+1)−S(i)<=1;

用链式前向星跑最长路即可

#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define pb push_back
#define REP(i,N) for(int i=0;i<(N);i++)
#define CLR(A,v) memset(A,v,sizeof A)
#define inf 0x3f3f3f3f
//////////////////////////////////////
const int N = +; int pos=;
struct node
{
int nex,to,v;
}edge[N]; int head[N];
void add(int a,int b,int v)
{
edge[++pos].nex=head[a];
head[a]=pos;
edge[pos].to=b;
edge[pos].v=v;
} int dis[N],vis[N];
int L,R;
void spaf(int s)
{
rep(i,L,R)
dis[i]=-inf;
dis[s]=;
queue<int>q;
q.push(s);
vis[s]=;
while(!q.empty())
{
int u=q.front();q.pop();
vis[u]=;
for(int i=head[u];i;i=edge[i].nex)
{
int v=edge[i].to;
if(dis[v]<dis[u]+edge[i].v)
{
dis[v]=dis[u]+edge[i].v;
if(!vis[v])
{
vis[v]=;
q.push(v);
}
}
}
}
}
int main()
{
int n;
while(~RI(n))
{
pos=;
CLR(head,);
CLR(vis,);
L=inf;
R=;
rep(i,,n)
{
int a,b,c;
RIII(a,b,c);a--;
add(a,b,c);
L=min(a,L);
R=max(R,b);
}
rep(i,L,R-)
add(i,i+,),add(i+,i,-);
spaf(L);
cout<<dis[R]<<endl;
}
return ;
}

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

  1. POJ1201 Intervals(差分约束)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 10966 Description You ...

  2. hdu 1384 Intervals (差分约束)

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. poj 1716 Integer Intervals (差分约束 或 贪心)

    Integer Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12192   Accepted: 514 ...

  4. zoj 1508 Intervals (差分约束)

    Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer interva ...

  5. poj 1201 Intervals(差分约束)

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

  6. poj 1201 Intervals——差分约束裸题

    题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...

  7. poj1201 Intervals——差分约束

    题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...

  8. POJ 2101 Intervals 差分约束

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27746   Accepted: 10687 Description You ...

  9. poj1201/zoj1508/hdu1384 Intervals(差分约束)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Intervals Time Limit: 10 Seconds      Mem ...

  10. hdu 1384 Intervals (差分约束)

    /* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...

随机推荐

  1. 读取Excel2003、Excel2007或更高级的兼容性问题 workbook 下载中文名称文件

    xls 使用HSSFWorkbook xlsx使用XSSFWorkbook 但是我使用XSSFWorkbook时没找到nuget包,引用不了,只能重新找办法,幸好workbook解决了我这个问题 // ...

  2. mpvue——引入vant_weapp组件

    克隆仓库 克隆后,将dist目录下的所有文件复制到项目中的/static/vant/目录下,vant目录是我自己创建为了区分的 git clone https://github.com/youzan/ ...

  3. MT【322】绝对值不等式

    已知 $a,b,c\in\mathbb R$,求证:$|a|+|b|+|c|+|a+b+c|\geqslant |a+b|+|b+c|+|c+a|$ 分析:不妨设$c=\max\{a,b,c\},\d ...

  4. 使用Sublime Text 3进行Markdown编辑+实时预览

    使用Sublime Text 3进行Markdown编辑+实时预览 安装软件包管理器 打开Sublime Text 3 同时按下 ctrl+` ,窗口底部出现一个小控制台 复制以下代码,粘贴到控制台的 ...

  5. python实现域名解析和归属地查询

    前言工作中有时要查询域名解析和获取域名相关IP归属地信息 安装依赖python2:pip install dnspythonpython3:python3 -m pip install -i http ...

  6. 一种使用 sprintf 导致死机的情况

    @2019-02-26 [小记] char temp[10] float money; sprintf(temp, "0.2f", money); 以上使用方法可能导致死机,原因是 ...

  7. centos安装node环境

    一.安装wget yum install -y wget 二.下载node最新的安装包 wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linu ...

  8. CAS实现单点登录

    1.简介 SSO单点登录 在多个相互信任的系统中,用户只需要登录一次就可以访问其他受信任的系统. 新浪微博与新浪博客是相互信任的应用系统. *当用户首次访问新浪微博时,新浪微博识别到用户未登录,将请求 ...

  9. Groovy 设计模式 -- 组合模式

    Composite Pattern http://groovy-lang.org/design-patterns.html#_chain_of_responsibility_pattern 组合模式, ...

  10. mui-选项卡+scroll滚动

    详细操作见代码: <!doctype html> <html> <head> <meta charset="UTF-8"> < ...