图论--差分约束--POJ 1201 Intervals】的更多相关文章

Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30971 Accepted: 11990 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 point…
Language:Default Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 43021   Accepted: 12075 Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse…
Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a straight line waiting for feed. The cows are standing in the same order as they are numbered, and sin…
Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound king.'' After nine months her child was born, and indeed, she gave birth to a nice son. Unfo…
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years ago. Draco established a line of defense called Grot. Grot is a straight line with N defense stations. Because of the cooperation of the stations, Zibu…
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> using namespace std; <<;…
题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都连着一条0的边. 别忘了约束条件不仅有s[ i ] - s[ i-1 ] >= 0,还有s[ i ] - s[ i - 1] <= 1! 别忘了s的范围不是n而是mx! #include<iostream> #include<cstdio> #include<cstr…
传送门:http://poj.org/problem?id=1201 题意: 有n个如下形式的条件:,表示在区间[, ]内至少要选择个整数点.问你满足以上所有条件,最少需要选多少个点? 思路:第一道差分约束题,有关差分约束知识详见https://blog.csdn.net/whereisherofrom/article/details/78922648(个人感觉这个博主写的挺好的) 令表示从区间[0,x]中选择的整数点个数,则有=c_i\rightarrow s_{b_i+1}-s_{a_i}>…
做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,50000]上,每一个三元组表示[ai,bi]之间至少要标记ci个数字,问至少要标记多少个数字. 在学习差分约束的童鞋,建议看一下:09年姜碧野的<SPFA算法的优化及应用>,06年冯威的<浅析差分约束系统>,不过后者看起来较难搞懂,也可以看http://ycool.com/post/m2u…
<题目链接> 题目大意:给你$n$段区间,$a_i,b_i,c_i$ 表示在 $[a_i,b_i]$ 区间内至少要选择$c_i$个点.现在问你在满足这n个条件的情况下,最少要选多少个点? 解题分析: 经典的差分约束.本问题需要满足的不等式有:$s[b[i]]-s[a[i]-1]\geq c[i],0\leq s[i]-s[i-1]\leq 1$,其中s[i]表示到第i个位置为止,所选择的点的个数. 转换一下,就能够得到: $s[b[i]]\geq s[a[i]-1]+c[i]$ $s[i]\g…
懒得复制,戳我戳我 Solution: 这道题就是一个板子题 抽象成第\(a\)至第\(b\)间选择数的个数为\(c\),我们就可以用前缀和来表示,这样就可以得到不等式\(s[b]-s[a-1]>=c\),然后就可以差分约束了 这一个约束条件不够,因为每个数只能选择一次,所以补上\(s[i+1]-s[i]>=0\)和\(s[i+1]-s[i]<=1\),注意存在\(0\)与\(-1\)的连边,我们可以吧\(-1\)拿出来用大于\(50000\)的数字来表示 然后求单元最大路径,随后的\(…
关于差分约束详情可阅读:http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html 题意: 给定n个区间[L,R], 每个区间至少放w个球, 问最后整个区间最少要放多少个球. 分析: 假设d[i] 是 [1,i] 至少有多少个点被选中, 特殊地, d[0] = 0. 每个区间的描述可以转化为d[R] - d[L-1] >= w.(因为d[L]也要选中, 左闭右闭区间, 所以要减d[L-1])因为d[i]描述了一个求和函数,所…
设s为前缀和,首先显然的条件是\[ s_{bi}-s_{ai-1}>=c \],然后隐含的是\[ s_i-s_{i-1}>=0 s_i-s_{i-1}<=1 \] 然后根据差分约束,就是连边(bi,ai-1,-li),(i-1,i,1),(i,i-1,0) spfa跑最长路最后输出相反数即可,注意n是起点,min是终点,跑最短路(不会有负环) #include<iostream> #include<cstdio> #include<queue> usi…
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai,bi]这个区间的整数至少有ci个.如果存在这样的序列,请求出满足题目要求的最短的序列长度是多少. 思路: 设s[i]为从1~i的整数个数. 这样对于区间[ a , b]显然有 S[b+1] - S[a] >=c[i] (为什么是b+1?因为闭区间b也要选上呀) 然后还有 0<= S[B+1]-S[…
题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为>=形式,那么显然有xvi >= xui-1 + ci,那么就在约束图中连一条(ui-1, vi, ci)的边:当然不要忘记隐含的不等式:xi >= xi-1 + 0;   xi-1 >= xi -1. 建完图后SPFA求最长路径即可 代码 [cpp] #include <iostr…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6574   Accepted: 3177 Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a…
Intervals Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Submit Status 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 en…
Time Limit: 2000MSMeamory Limit: 65536K Total Submissions: 27949Accepted: 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 integer…
[bzoj2330]: [SCOI2011]糖果 恩..就是裸的差分约束.. x=1 -> (A,B,0) (B,A,0) x=2 -> (A,B,1)  [这个情况加个A==B无解的要特判] x=3 -> (B,A,0)  [恩这个是不少于一开始zz建反了] x=4 -> (B,A,1) x=5 -> (A,B,0) 然后源点到所有点建1的边[恩据说有条链所以要反着连]跑最长路就好了 /* http://www.cnblogs.com/karl07/ */ #include…
Problem Description Ali has taken the Computer Organization and Architecture course this term. He learned that there may be dependence between instructions, like WAR (write after read), WAW, RAW. If the distance between two instructions is less than…
Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20779   Accepted: 7863 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…
题意: 有一个集合Z,其元素都是整整数,但是数量未知.现有n个约束,形如 [a,b]=c 表示整数区间[a,b]中有c个元素在Z中出现.问集合Z最小可能含多少个元素? 思路: 对于所给的区间 cnt[b-a]>=k这可以保证了该区间内个数不少于k.但是由于两边都是闭区间,所以要变cnt[b-(a-1)]>=k,表示b到a之间的个数.也就是说,转成式子是b-(a-1)>=k,变换一下为(a-1)-b<=-k,就满足常见的式子b-a<=k啦,可以建边b指向(a-1),权值为-k.…
Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24099   Accepted: 9159 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 po…
题意:有n个区间[a,b],每个区间有一个值c.找一个集合中的元素使得每个区间至少有c个元素在这个集合中,问最小的集合大小. 思路:设d[i+1]表示0到i有多少个数在这个集合中,显然对于每个区间,d[b+1]-d[a]>=c,才能符合题目的要求.但是这样并不能使得所有集合都联系起来.继续挖掘条件,根据d[]的定义可得,0<=d[i+1]-d[i]<=1. 由此可得三个不等式: d[b+1]-d[a]>=c d[i+1]-d[i]>=0 d[i]-d[i+1]>=-1…
差分约束系统. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<algorithm> using namespace std; ; map<int, int> jz[maxn]; vector<int>ljb[maxn]; int di…
相交区间选尽量少的点是可以贪心的,右端点排序以后,尽量往右边放可以得到可以使得点在区间尽可能多. 但是我只想到了O(n)的维护方法.(数据比较水,能过... 或者是前缀和可以写sum(bi) - sum(ai-1) ≥ ci 再加上前缀和的单调性 sum(i) - sum(i-1) ≥ 0 以及一个点只能选一次 sum(i-1) - sum(i) ≥ -1. 左边具有可加性的,根据对偶性:min ( sum(n) - sum(0) ) ≥ max( c ) 右边就是求一个最长路了. 复杂度:O(…
[POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23817   Accepted: 9023 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p…
Integer Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12192   Accepted: 5145 Description An integer interval [a,b], a < b, is a set of all consecutive integers beginning with a and ending with b. Write a program that: finds t…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4841    Accepted Submission(s): 1815 Problem Description You are given n closed, in…
1716 -- Integer Intervals 跟之前个人赛的一道二分加差分约束差不多,也是求满足条件的最小值. 题意是,给出若干区间,需要找出最少的元素个数,使得每个区间至少包含两个这里的元素. 做法就是建立(b)->(a)=-2,(i)->(i+1)=1,(i+1)->(i)=0的边,然后跑一次spfa即可. 做完的时候,因为队列开太小,所以re了一次. 代码如下: #include <iostream> #include <algorithm> #inc…