POJ——T 3159 Candies】的更多相关文章

题目链接:http://poj.org/problem?id=3159 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 k…
http://poj.org/problem?id=3159 Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 33328   Accepted: 9349 Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of fly…
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…
3159 -- Candies 明明找的是差分约束,然后就找到这题不知道为什么是求1~n的最短路的题了.然后自己无聊写了一个heap,518ms通过. 代码如下: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ; ; struct Edge { int t, nx, c; } edge[M]; int eh[…
题目链接:http://poj.org/problem?id=3159 题意:给出m给 x 与y的关系.当中y的糖数不能比x的多c个.即y-x <= c  最后求fly[n]最多能比so[1] 多多少糖? 差分约束问题, 就是求1-n的最短路,  队列实现spfa 会超时了,改为栈实现,就可以 有负环时,用栈比队列快 数组开小了,不报RE,报超时 ,我晕 #include <iostream> #include <cstdlib> #include <cstdio>…
Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 20067   Accepted: 5293 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 b…
http://poj.org/problem?id=3159 题意:有向图,第一行n是点数,m是边数,每一行有三个数,前两个是有向边的起点与终点,最后一个是权值,求从1到n的最短路径. 思路:这个题让会神给讲的,用的dijkstra,看的网上很多用SPFA的. 关于SPFA:http://www.cnblogs.com/devtang/archive/2011/08/25/spfa.html http://blog.csdn.net/chenjiang492943457/article/deta…
原题地址:http://poj.org/problem?id=3159 题意大概是班长发糖果,班里面有不良风气,A希望B的糖果不比自己多C个.班长要满足小朋友的需求,而且要让自己的糖果比snoopy的尽量多. 比如现在ABCD四个小朋友,B的糖果不能超过A的5个,如果A的史努比,D是班长,那么班长最多比史努比多7个糖果,而不是5+4+1=9个. 因为如果是9个,就不满足D-A<=(D-C)+(C-A)<=7的条件. 不懂的可以翻一下算法导论,上面有差分约束的定义和证明,总之这是一个求最短路的问…
题目链接:http://poj.org/problem?id=3159 题目大意:给n个人派糖果,给出m组数据,每组数据包含A,B,C三个数,意思是A的糖果数比B少的个数不多于C,即B的糖果数 - A的糖果数<=C . 最后求n 比 1 最多多多少颗糖果. 解题思路:经典差分约束的题目,具体证明看这里<数与图的完美结合——浅析差分约束系统>. 不妨将糖果数当作距离,把相差的最大糖果数看成有向边AB的权值,我们得到 dis[B]-dis[A]<=w(A,B).看到这里,我们可以联想到…
http://poj.org/problem?id=3159 题目大意: n个小朋友分糖果,你要满足他们的要求(a b x 意思为b不能超过a x个糖果)并且编号1和n的糖果差距要最大. 思路: 嗯,我先揭发一下,1号是分糖果的孩子,班长大人!(公报私仇啊...,欺负N号的小朋友~ 好吧,我开玩笑的) 嗯,这题要求最短路径.为啥是最短?你以前都在玩最长呀~ 因为这题要求的是最大的.图的三角不等式有:d[v]- d[u]<=w(u,v);  d[v]<=d[u]+w(u,v); 即而松弛的条件为…