题目链接:http://poj.org/problem?id=3169 题目大意:n头牛,按编号1~n从左往右排列,可以多头牛站在同一个点,给出ml行条件,每行三个数a b c表示dis[b]-dis[a]<=c,接下来有md行条件,每行三个数a b c,表示dis[b]-dis[a]>=c.求出出第一头牛和第n头牛的最大可能距离.若不可能把所有牛排成一排即条件有矛盾,则输出“-1”,若第一头牛和第n头牛的距离可以无限大,则输出“-2”. 解题思路:第二道差分约束的题目.根据题目给出的三个约束…
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…
Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15349 Accepted: 7379 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…
During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the kids loved candies very much and often compared t…
Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11612 Accepted: 5550 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…
题目链接:http://poj.org/problem?id=3169 差分约束的解释:http://www.cnblogs.com/void/archive/2011/08/26/2153928.html 我也不是特别理解,要是给你a - b <= k 就建一条b->a权值为k的有向边,要是a - b >= k 就建一条a -> b边权是-k的有向边,要是让你求n到1的最大差,就是让你求1到n的最短距离. 差分约束系统有两种方式可以求解,最短路和最长路.当我们把不等式整理成d[a…
http://poj.org/problem?id=3169 http://acm.hdu.edu.cn/showproblem.php?pid=3592 题目大意: 一些母牛按序号排成一条直线.有两种要求,A和B距离不得超过X,还有一种是C和D距离不得少于Y,问可能的最大距离.如果没有输出-1,如果可以随便排输出-2,否则输出最大的距离. 思路: 对于第一种 B - A <=X 第二种有 D - C >=Y也就是 C-D<=-Y 还有就是题目要求的是按照序号升序排. 然后又不等式3…