Intervals 差分约束
题意:给定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 差分约束的更多相关文章
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- hdu 1384 Intervals (差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- poj 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- zoj 1508 Intervals (差分约束)
Intervals Time Limit: 10 Seconds Memory Limit: 32768 KB You are given n closed, integer interva ...
- poj 1201 Intervals(差分约束)
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...
- poj 1201 Intervals——差分约束裸题
题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...
- poj1201 Intervals——差分约束
题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...
- POJ 2101 Intervals 差分约束
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 27746 Accepted: 10687 Description You ...
- poj1201/zoj1508/hdu1384 Intervals(差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Intervals Time Limit: 10 Seconds Mem ...
- hdu 1384 Intervals (差分约束)
/* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...
随机推荐
- MT【314】正切比值
(05复旦)已知三角形$\Delta ABC$满足$\tan A:\tan B:\tan C=1:2:3$,求$\dfrac{AC}{AB}$____ 解答:设$x=tan A$,利用恒等式$\tan ...
- CF908D New Year and Arbitrary Arrangement(期望Dp+数学)
题目大意:给你一个空字符串,你有\(\frac{pa}{pa+pb}\)的概率往字符串最后面加个\(a\),\(\frac{pb}{pa+pb}\)的概率往字符串最后面加个\(b\),当子序列\(ab ...
- P1962 斐波那契数列
题面是这样的,其实斐波那契我们之前也有接触过,并不是什么太陌生的玩意,第一个想到的方法其实是用递归来做,这样的话其实是非常轻松的,but同志们你们有没有关注过这样一个鬼东西 你以为蓝题是让你切着玩的吗 ...
- Django自定义分页
分页 自定义分页 稳扎稳打版 def book(request): # 从URL取参数(访问的页码) page_num = request.GET.get("page") try: ...
- Loj 10115 「一本通 4.1 例 3」校门外的树 (树状数组)
题目链接:https://loj.ac/problem/10115 题目描述 原题来自:Vijos P1448 校门外有很多树,学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的 ...
- 20190211 模拟训练 A. 大猫咪
好题 2.11考试
- Linux下查看Nginx安装目录、版本号信息及当前运行的配置文件
Linux环境下,怎么确定Nginx的安装路径 输入命令行: ps -ef | grep nginx 摁回车,将出现如下图片: master process 后面的就是的 /data/software ...
- eMMC真能优化成UFS?谈谈手机闪存的文件系统
和UFS闪存相比,eMMC的性能更弱,同一型号的手机混用这两种规格的闪存,让一些消费者感到了不满.对此,厂商称通过优化,eMMC的产品也可以获得优秀的体验.这个优化到底是怎么回事?根据以往的一些宣传, ...
- kubernetes云平台管理实战: 服务发现和负载均衡(五)
一.rc控制器常用命令 1.rc控制器信息查看 [root@k8s-master ~]# kubectl get replicationcontroller NAME DESIRED CURRENT ...
- 第十二节: 总结Quartz.Net几种部署模式(IIS、Exe、服务部署【借助TopSelf、服务类】)
一. IIS部署 比如在MVC框架中集成了Quartz.Net定时调度,此时该调度系统会随着MVC框架被挂在IIS下,IIS会进程回收,所以大部分开发都会遇到Quartz挂在IIS下一段时间不好用. ...