题意:给定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. Elasticsearch 创建以及修改索引结构

    从问题出发,这篇内容可以解决以下几个问题: 一:如何开启关闭Es索引(数据库)? 二:如何创建索引(数据库)结构? 三:如何向已有索引(数据库)中添加类型(表)结构? 四:如何向已有类型(表)中添加新 ...

  2. 项目管理——WBS工作分解法

    首先我们要了解什么是WBS工作分解法 工作分解结构(Work Breakdown Structure,简称WBS)跟因数分解是一个原理,就是把一个项目,按一定的原则分解,项目分解成任务,任务再分解成一 ...

  3. Eclipse 添加 lib (导入 .jar 包)

    1.将要添加的 jar 包直接拖到 WEB-INF/lib 目录里. 2.在项目上右键,依次选择[Build Path]--[Configure Build Path...]-- [Libraries ...

  4. Flask进阶

    Threading.local 作用:为每个线程创建一个独立的空间,使得线程对自己的空间中的数据进行操作(数据隔离). 应用: flask上下文管理中的local中比这更高级,为协程. DBUtils ...

  5. IaaS,PaaS,SaaS 的区别(转)

    越来越多的软件,开始采用云服务. 云服务只是一个统称,可以分成三大类. IaaS:基础设施服务,Infrastructure-as-a-service PaaS:平台服务,Platform-as-a- ...

  6. SQL Server 跨服务器操作

    Ø  简介 在工作中编写 SQL 时经常会遇到跨库或跨服务器操作,比如查询时,通过 A 服务器的某张表关联 B 服务器某张表,进行连接查询.或者从另一台服务器中的数据,对当前数据库中的数据进行 CRU ...

  7. Win7 x64位打开VirtualBox报错处理。

    错误代码如下: Failed to instantiate CLSID_VirtualBox w/ IVirtualBox, but CLSID_VirtualBox w/ IUnknown work ...

  8. 程序通过ReportViewer对象来调用reporting services并导出pdf文件

    ReportViewer tempReportViewer = new ReportViewer(); tempReportViewer.ProcessingMode = ProcessingMode ...

  9. EmbeddedSolrServer的使用与solor6.3.0的使用

    1.    到solr官网下载对应版本的solr: https://lucene.apache.org/solr/ 我下载的是:6.3.0版本(需要JDK8),solr默认集成了jetty容器,而且在 ...

  10. php 默认保几位小数,末尾为0去掉

    计算保留几位小数,末位为0舍去 // 计算 默认保留1位小数 protected function getSprintf($value,$count,$digit = 1) { $num = 0; i ...