THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8693    Accepted Submission(s): 2246 Problem Description You have been given a matrix CN*M, each element E of CN*M is positive…
题意:给定一个最大400*400的矩阵,每次操作可以将某一行或某一列乘上一个数,问能否通过这样的操作使得矩阵内的每个数都在[L,R]的区间内. 析:再把题意说明白一点就是是否存在ai,bj,使得l<=cij*(ai/bj)<=u (1<=i<=n,1<=j<=m)成立. 首先把cij先除到两边去,就变成了l'<=ai/bj<=u',由于差分约束要是的减,怎么变成减法呢?取对数呗,两边取对数得到log(l')<=log(ai)-log(bj)<=l…
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5437    Accepted Submission(s): 1372 Problem Description You have been given a matrix CN*M, each element E of CN*M is positive…
题意: 给一个n*m矩阵,每个格子上有一个数字a[i][j],给定L和U,问:是否有这样两个序列{a1...an}和{b1...bn},满足 L<=a[i][j]*ai/bj<=U .若存在输出yes,否则no. 思路: 能够得到的是一堆不等式,那么可以用最短路来解决差分约束系统.但是a[i][j]*ai/bj<=U是除的,得提前变成减的才行.可以用对数log来解决,先不管a[i][j],logai-logbj<=U不就行了?可以得到: (1)logai - logbj<=U…
差分约束系统. 根据题意,可以写出不等式 L <= (Xij * Ai) / Bj <= U 即 Ai/Bj<=U/Xij和Ai/Bj>=L/Xij 由于差分约束系统是减法..除法变减法可以用对数来解决. 两个式子两边取对数,可以写成log(Ai)-log(Bj)<=log(U/Xij)和log(Ai)-log(Bj)>=log(L/Xij) log(Ai)和log(Bj)看作两个节点.编号分别为i和n+j,建立有向图,判断有没有负环存在.  if(summ[hh]&g…
You have been given a matrix C N*M, each element E of C N*M is positive and no more than 1000, The problem is that if there exist N numbers a1, a2, … an and M numbers b1, b2, …, bm, which satisfies that each elements in row-i multiplied with ai and e…
You have been given a matrix C N*M, each element E of C N*M is positive and no more than 1000, The problem is that if there exist N numbers a1, a2, - an and M numbers b1, b2, -, bm, which satisfies that each elements in row-i multiplied with ai and e…
题目请戳这里 题目大意:给一个n*m的矩阵,求是否存在这样两个序列:a1,a2...an,b1,b2,...,bm,使得矩阵的第i行乘以ai,第j列除以bj后,矩阵的每一个数都在L和U之间. 题目分析:比较裸的差分约束.考虑那2个序列,可以抽象出m+n个点.乘除法可以通过取对数转换为加减法.然后就可以得到约束关系: 对于矩阵元素cij,有log(L) <= log(cij) + ai - bj <= log(U),整理可得: ai - bj <= log(U) - log(cij),n+…
// 题目描述:一个项目被分成几个部分,每部分必须在连续的天数完成.也就是说,如果某部分需要3天才能完成,则必须花费连续的3天来完成它.对项目的这些部分工作中,有4种类型的约束:FAS, FAF, SAF和SAS.两部分工作之间存在一个FAS约束的含义是:第一部分工作必须在第二部分工作开始之后完成: Xa+Ta>=XbFAF约束的含义是:第一部分工作必须在第二部分工作完成之后完成: Xa+Ta>=Xb+TbSAF的含义是:第一部分工作必须在第二部分工作完成之后开始: Xa>=Xb+TbS…
Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5488    Accepted Submission(s): 1999 Problem Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.…
POJ 1364 题解:最短路式子:d[v]<=d[u]+w 式子1:sum[a+b+1]−sum[a]>c      —      sum[a]<=sum[a+b+1]−c−1       —      (a+b+1,a) −c−1 式子2:sum[a+b+1]−sum[a]<c      —      sum[a+b+1]<=sum[a]+c−1       —      (a,a+b+1)  c−1 注意:先移项,移项完后再处理没有等于的情况. 附加式:sum[0]&l…
题目链接:https://cn.vjudge.net/contest/276233#problem/C 题目大意:有n层楼,给你每个楼的高度,和这个人单次的最大跳跃距离m,两个楼之间的距离最小是1,但是楼和楼之间的距离是能够调整的,现在有一个人,要从最矮的楼开始跳,每一次跳到比当前的楼高的楼上,然后问你在将所有的楼都走一遍的基础上,从第一个楼到最后一个楼之间的最远距离是多少? 思路:使用差分约束系统的相关知识, 我们可以建立如下不等式. 1,当相邻的时候,限制posA-posB>=1,也就是po…
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8016    Accepted Submission(s): 2092 Problem Description You have been given a matrix CN*M, each element E of CN*M is positive…
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7819    Accepted Submission(s): 2019 Problem Description You have been given a matrix CN*M, each element E of CN*M is positive…
[HDU 1529]Cashier Employment(差分约束系统) 题面 有一个超市,在24小时对员工都有一定需求量,表示为\(r_i\),意思为在i这个时间至少要有i个员工,现在有n个员工来应聘,每一个员工开始工作的时间为\(t_i(i \in [0,23])\),并持续8小时,问最少需要多少员工才能达到每一个时刻的需求.前一天16点后的人统计入下一天 分析 预备知识:(如果你了解过差分约束,可以直接跳过) 首先讲一下差分约束系统的基本定义:如果一个系统由n个变量和m个约束条件组成,形成…
https://vjudge.net/problem/UVA-11478 给定一个有向图,每条边都有一个权值.每次你可以选择一个结点v和一个整数d,把所有以v为终点的边的权值减小d,把所有以v为起点的边的权值增加d,最后让所有边的权值的最小值大于零且尽量大. 该死书上翻译错了 >0不是非负 WA好几次因为这个 考虑每条边的约束,di表示i的halum量 w-dv+du>0 dv-du<w 但求解这个差分约束系统只是让这组不等式成立,最长路和最短路控制的都是单个d的最值而不是最小值最大 那…
Layout 题目链接: Rhttp://acm.hust.edu.cn/vjudge/contest/122685#problem/S 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 straight line waitin…
HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4291 Description 给一个式子求结果.类似Fibonacci的公式g(n)=3*g(n-1)+g[n-2]. Input 给你n(1<=n<=1e18) Output 求g(g(g(n))) Sample Input 样例第一个就是0什么鬼,虽然没影响.…
Problem  UVA - 11090 - Going in Cycle!! Time Limit: 3000 mSec Problem Description You are given a weighted directed graph with n vertices and m edges. Each cycle in the graph has a weight, which equals to sum of its edges. There are so many cycles in…
Problem  UVA - 11478 - Halum Time Limit: 3000 mSec Problem Description You are given a directed graph G(V,E) with a set of vertices and edges. Each edge (i,j) that connects some vertex i to vertex j has an integer cost associated with that edge. Defin…
POJ 3159 Candies (图论,差分约束系统,最短路) Description 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…
题目链接:https://cn.vjudge.net/contest/276233#problem/A 差分约束系统,假设当前有三个不等式 x- y <=t1 y-z<=t2 x-z<=t3 我们可以将第一个式子和第二个式子结合起来,就变成了x-z<= t1+t2 ,然后x-z的最大差值就是min(t1+t2,t3)(因为要使得最终结果都满足两个不等式) 然后求最小的过程(求差最大),就可以通过最短路的算法实现. 题目大意:给你n代表有n头牛,然后ml和md,接下来ml行,每行有三…
幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他的多,于是在分配糖果的时候,lxhgww需要满足小朋友们的K个要求.幼儿园的糖果总是有限的,lxhgww想知道他至少需要准备多少个糖果,才能使得每个小朋友都能够分到糖果,并且满足小朋友们所有的要求. Input 输入的第一行是两个整数N,K. 接下来K行,表示这些点需要满足的关系,每行3个数字,X,A,B. 如果X=1, 表…
King Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2216    Accepted Submission(s): 999 Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my ch…
Cashier Employment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1214    Accepted Submission(s): 537 Problem Description A supermarket in Tehran is open 24 hours a day every day and needs a nu…
差分约束系统讲解看这里:http://blog.csdn.net/xuezhongfenfei/article/details/8685313 模板题,不多说.要注意的一点是!!!对于带有within的语句,要建立两个不等式!!!x要在y开始的z分钟内开始的话,x<=y+z 并且 x>=y.别忘了. spfa判负权回路. In most recipes, certain tasks have to be done before others. For each task, if we are…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2330 类似于题目中这种含有不等式关系,我们可以建立差分约束系统来跑最长路或最短路. 对于一个不等式$X_1-X_2>=a$我们可以看成是$X_1>=X_2+a$,把$X_1$和$X_2$看成两个点,我们可以发现这个关系跟最长路中的$dis[v]>=dis[u]+w[i]$很像,就是最长路中的点一定满足这样的关系. 所以我们就按着这个思路,先把关于点$X_1$,$X_2$和边$a$…
[POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7569   Accepted: 2856 Description A supermarket in Tehran is open 24 hours a day every day and needs a number of cashiers to f…
http://poj.org/problem?id=1201 题意:给定n个整数闭区间[a,b]和n个整数c,求一个最小的整数集合Z,满足Z里边的数中范围在闭区间[a,b]的个数不小于c个. 思路:根据题目描述,可建模成一个差分约束系统. 设S[i]表示小于等于i的整数的个数,R表示最大的右端点值,L表示最小的左端点值: 则 S[b] - S[a-1] >= c; 转化成:S[a-1] - S[b] <= -c;...... (1) S[i] - S[i-1]  <= 1; ......…
2330: [SCOI2011]糖果 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 5395  Solved: 1750[Submit][Status][Discuss] Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他的多,于是在分配糖果的时候,lxhgww需要满足小朋友们的K个要求.幼儿园的糖果…