政务桌面应用系统开发提升政府服务效率的关键所在
631
2022-08-29
bzoj1986 [USACO2004 Dec] Dividing the Path 划区灌溉
Description
Farmer John’s cows have discovered that the clover growing along the ridge of the hill in his field is particularly good. To keep the clover watered, Farmer John is installing water sprinklers along the ridge of the hill. To make installation easier, each sprinkler head must be installed along the ridge of the hill (which we can think of as a one-dimensional number line of length L (1 <= L <= 1,000,000); L is even). Each sprinkler waters the ground along the ridge for some distance in both directions. Each spray radius is an integer in the range A..B (1 <= A <= B <= 1000). Farmer John needs to water the entire ridge in a manner that covers each location on the ridge by exactly one sprinkler head. Furthermore, FJ will not water past the end of the ridge in either direction. Each of Farmer John’s N (1 <= N <= 1000) cows has a range of clover that she particularly likes (these ranges might overlap). The ranges are defined by a closed interval (S,E). Each of the cow’s preferred ranges must be watered by a single sprinkler, which might or might not spray beyond the given range. Find the minimum number of sprinklers required to water the entire ridge without overlap.
约翰的奶牛们发现山督上的草特别美味.为了维持草的生长,约翰打算安装若干喷灌器.为简化问题,山脊可以看成一维的数轴,长为L(1≤L≤10^6),而且L-定是一个偶数.每个喷灌器可以双向喷灌,并有确定的射程,该射程不短于A,不长于B,A,B(1≤A≤B≤103)都是给出的正整数.它所在位置的两边射程内,都属它的灌溉区域.现要求山脊的每一个区域都被灌溉到,而且喷灌器的灌溉区域不允许重叠, 约翰有N(1≤N≤10^3)只奶牛,每一只都有特别喜爱的草区,第i奶牛的草区是[Si,Ei],不同奶牛的草区可以重叠.现要求,每只奶牛的草区仅被一个喷灌器灌溉. 寻找最少需要的喷灌器数目.
Input
Line 1: Two space-separated integers: N and L * Line 2: Two space-separated integers: A and B * Lines 3..N+2: Each line contains two integers, S and E (0 <= S < E <= L) specifying the start end location respectively of a range preferred by some cow. Locations are given as distance from the start of the ridge and so are in the range 0..L.
Output
Line 1: The minimum number of sprinklers required. If it is not possible to design a sprinkler head configuration for Farmer John, output -1.
Sample Input
2 8 1 2 6 7 3 6 Sample Output
3 HINT
这个方程满足f[i]=minf[k]+1;
所以我们应该用单调队列处理出这个k来
求一下 我可以划分多少灌溉的区域 如果不加奶牛的限制 就可以数学方法算一算的 但是奶牛喜爱区域的开区间内只允许有一个灌溉的,那么我们认为这个区域为不可划分的就好了啊 设f[i]表示灌溉前i个区域需要最少的灌溉器的数目 按照题意的话 因为牛喜爱的牧场的开区间内是不能有多个灌溉区的 所以啊 我们就先给打上标记方便以后处理的 还有就是需要注意一下题目中给的都是到一号的距离 所以存在0的情况
每个f[i]不能刚算出来就弹队尾+进队尾,因为此时下一个位置为 i+2 ,可能会把能够转移到i+2的合法状态弹出去,而f[i]是不能转移到f[i+2]的!(因为有a的限制)所以会造成f[i+2]计算错误(当然f[l]就也有可能出错了。事实上由于我们维护的队列是一个合法状态区间,所以目前不合法的状态不应该进队,而是应该在每次更新f[i]之前让 f[i-2*a] 进队,这样可以保证队列中所有节点都为合法状态。
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~