题意:给定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. Django+Vue打造购物网站(七)

    个人中心功能开发 drf文档注释 http://www.django-rest-framework.org/topics/documenting-your-api/ 动态设置serializer和pe ...

  2. [NOIp2016] 换教室

    题目类型:期望\(DP\) 传送门:>Here< 题意:现有\(N\)个时间段,每个时间段上一节课.如果不申请换教室,那么时间段\(i\)必须去教室\(c[i]\)上课,如果申请换课成功, ...

  3. 2.3 os 模块

    目录 2.3.1 功能 2.3.2 常用方法 2.3.2.1 创建相关 2.3.2.2 切换相关 2.3.2.3 查看相关 2.3.2.4 编辑相关 2.3.2.5 删除相关 2.3.1 功能 2.3 ...

  4. Magento 2 创建 Widget

    Widget是一个更好的工具,可以将内容插入或编辑到CMS页面块或页面中. 什么是小部件? 小部件是Magento 2配置中的强大功能.作为商店管理员,您可以利用小部件来改善生动界面下的店面.小部件允 ...

  5. LoadRunner【第四篇】参数化

    参数化的定义及使用场景 定义:将脚本中的特定值用变量替代,该变量值是变化的(注意:这个值是我们自己创建的,不是服务器返回的). 使用参数化: 1.业务考虑,不允许相同信息 2.真实模拟不同用户 3.真 ...

  6. 洛谷P2822 组合数问题(题解)

    https://www.luogu.org/problemnew/show/P2822(题目传送) 先了解一下有关组合数的公式:(m在上,n在下) 组合数通项公式:C(n,m)=n!/[m!(n-m) ...

  7. 时间函数(1):time,ctime,gmtime,localtime

    asctime(将时间和日期以字符串格式表示) #include<time.h> 定义函数 char * asctime(const struct tm * timeptr); 函数说明 ...

  8. css 函数

    css还有一些强大的函数: 1. calc 可以混合多种单位来计算 div { font-size: calc(100vw/5 + 1rem - 100px) } 2. max.min.clamp m ...

  9. webserver Etcd Cluster / CoreOS etcd / macOS etcd

    s https://coreos.com/etcd/ https://coreos.com/etcd/docs/latest/ macOS mojave etcd 003deMac-mini:~ ma ...

  10. CMDB服务器管理系统【s5day92】:定制表头

    一.目录结构 二.获取数据,模板语言渲染 web\views.py import json from django.shortcuts import render,HttpResponse from ...