hdu-3592 World Exhibition(差分约束)】的更多相关文章

Schedule Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1085    Accepted Submission(s): 448Special Judge Problem Description A project can be divided into several parts. Each part shoul…
类型:给出一些形如a−b<=k的不等式(或a−b>=k或a−b<k或a−b>k等),问是否有解[是否有负环]或求差的极值[最短/长路径].例子:b−a<=k1,c−b<=k2,c−a<=k3.将a,b,c转换为节点:k1,k2,k3转换为边权:减数指向被减数,形成一个有向图: 由题可得(b−a) + (c−b) <= k1+k2,c−a<=k1+k2.比较k1+k2与k3,其中较小者就是c−a的最大值.由此我们可以得知求差的最大值,即上限被约束,此时我…
King Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1645    Accepted Submission(s): 764 Problem Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The quee…
Problem - 1384 好歹用了一天,也算是看懂了差分约束的原理,做出第一条查分约束了. 题意是告诉你一些区间中最少有多少元素,最少需要多少个元素才能满足所有要求. 构图的方法是,(a)->(b+1)=c.还有就是所有的相邻的点都要连上(i+1)->(i)=0,(i)->(i+1)=-1.因为我对点离散了,所以就变成(rx[i])->(rx[i+1])=rx[i]-rx[i+1]. 代码如下: #include <cstdio> #include <cstr…
World Exhibition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2162    Accepted Submission(s): 1063 Problem Description Nowadays, many people want to go to Shanghai to visit the World Exhibiti…
题意: 有n个人在排队,按照前后顺序编号为1~n,现在对其中某两人的距离进行约束,有上限和下限,表示dis[a,b]<=c或者dis[a,b]>=c,问第1个人与第n个人的距离最多可能为多少?(若INF则输出-2,若冲突则输出-1,否则输出距离) 思路: 建图时都将约束转成a-b<=c的标准形式,然后建一条b->a的边,权为c.然后求最短路,注意最短路跑出来的结果却是最远的合法距离,而不是最短距离.本题无需添加辅助边,只要到达不了n,则距离为INF,输出-2,若有负环,那肯定是冲突…
题目链接 \(Description\) 给定一天24h 每小时需要的员工数量Ri,有n个员工,已知每个员工开始工作的时间ti(ti∈[0,23]),每个员工会连续工作8h. 问能否满足一天的需求.若能,输出最少需要多少员工. \(Solution\) 参考. 既然给的是开始工作时间,那么就先根据开始时间做 设Ai表示在i时开始工作的人数(未知),Bi表示i时可工作人数的上限(已知) 那么有:(注意可以跨天) A[i-7]+A[i-6]+...+A[i-1]+A[i] >= R[i] (7 <…
题目链接: World Exhibition Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) Problem Description   Nowadays, many people want to go to Shanghai to visit the World Exhibition. So there are always a lot of people who are…
Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4292    Accepted Submission(s): 1624 Problem Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.…
这题建图没什么特别 x个条件:Sb-Sa<=c y个条件:Sa-Sb<=-c 题目问的是.1和n之间的关系. 有负环的话,整个就不可能成立,输出-1 假设图是连通的(1到n是连通的),就输出d[n] 不连通就是题目中说-2的情况. 原来我们建图一般加入一个附加结点,或者開始就把全部点入队,就是考虑到不连通的问题,所以加入一个没有意义的条件. #include <iostream> #include <cstring> #include <string> #i…
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…
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.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1531 差分约束的题之前也碰到过,刚好最近正在进行图论专题的训练,就拿来做一做. ①:对于差分不等式,a - b <= c ,建一条 b 到 a 的权值为 c 的边,求的是最短路,得到的是最大值 ②:对于不等式 a - b >= c ,建一条 b 到 a 的权值为 c 的边,求的是最长路,得到的是最小值 ③:存在负环的话是无解 .④:求不出最短路(dist[ ]没有得到更新)的话是任意解 说明一下为…
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…
I - 动物狂想曲 HDU - 6252 雷格西桑和路易桑是好朋友,在同一家公司工作.他们总是一起乘地铁去上班.他们的路线上有N个地铁站,编号从1到N.1站是他们的家,N站是公司. 有一天,雷格西桑起床晚了.当他来到车站时,路易桑已经离开X分钟了.雷格西桑非常着急,于是他开始和路易桑聊天,交流他们的位置.内容是雷格西桑在A站和B站之间,路易桑在C站和D站之间. B等于A+ 1这意味着雷格西在A站和A+1之间, 或B等于A这意味着雷格西就是在车站A,反之亦然对于C和D同理.更重要的是,他们交流的时…
思路:首先就是判断是否有奇环,若存在奇环,则输出No. 然后用差分约束找是否符合条件. 对于e(i,j)属于E,并且假设顶点v[i]为正数,那么v[i]-v[j]>=T--->v[j]-v[i]<=-T; 对于e(i,j)不属于E,并且假设顶点v[i]为正数,那么v[i]-v[j]<=T-1; 以0号点为参照点,若果v[i]为负数,那么v[0]-v[i]<=T-1;  v[i]-v[0]<=0; 若果v[i]为正数,那么v[i]-v[0]<=T-1;  v[0]-…
题意:给定一个最大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…
Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4181    Accepted Submission(s): 1577 Problem Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.…
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…
King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12056   Accepted: 4397 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 kin…
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…
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★2544 最短路 基础最短路★3790 最短路径问题基础最短路★2066 一个人的旅行基础最短路(多源多汇,可以建立超级源点和终点)★2112 HDU Today基础最短路★1874 畅通工程续基础最短路★1217 Arbitrage 货币交换 Floyd (或者 Bellman-Ford 判环)★124…
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ 2544    最短路  基础最短路★ 3790    最短路径问题基础最短路★ 2066    一个人的旅行基础最短路(多源多汇,可以建立超级源点和终点)★ 2112    HDU Today基础最短路★ 1874    畅通工程续基础最短路★ 1217    Arbitrage   货币交换…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9687   Accepted: 4647 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…
基础差分约束. /* 3592 */ #include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdio> #include <cstring> using namespace std; #define MAXN 1005 #define MAXE 20005 #define INF 0x3f3f3f3f typede…
https://www.cnblogs.com/31415926535x/p/10463112.html 很早之前学最短路的时候就看了一眼差分约束,,当时以为这种问题不怎么会出现,,而且当时为了只为了学最短路,,所以就没有怎么做题,,知道是什么,但是不会建图使用,, 然后上一次做cf就碰到了,,虽然那道题不只是差分约束能解决还卡时间,,但是万一以后还出现这种题,,只是知道是这个类型的题却不知道如何下手也相当于是不会啊,,所以抽时间重新看了看这块的内容,,做几道题,,顺便背一背最短路的板子,,好久…
http://acm.hdu.edu.cn/showproblem.php?pid=4109 Instrction Arrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2196    Accepted Submission(s): 900 Problem Description Ali has taken the Co…
http://acm.hdu.edu.cn/showproblem.php?pid=1531 King Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1992    Accepted Submission(s): 928 Problem Description Once, in one kingdom, there was a quee…
http://acm.hdu.edu.cn/showproblem.php?pid=1529 Cashier Employment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1489    Accepted Submission(s): 672 Problem Description A supermarket in Tehran…