题目链接:http://poj.org/problem?id=3159 题意:给n个人派糖果,给出m组数据,每组数据包含A,B,c 三个数,意思是A的糖果数比B少的个数不多于c,即B的糖果数 - A的糖果数<= c . 最后求n比1最多多多少糖果. 可以从条件中的 B-A<=c及B<=A+c最后要达成这个条件就是要当B>A+c时B=A+c即可 所以差不多就是求最短路.这题中还有一些优化比如 if(vis[u]) continue;这个避免了u点的重复查找 #include <…
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[…
Candies 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J 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 fl…
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 题意大概是班长发糖果,班里面有不良风气,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/searchproblem 题目大意: 飞天鼠是班长,一天班主任买了一大包糖果,要飞天鼠分发给大家,班里面有n个人,但是学生A认为学生B比自己多的糖果数目不应该大于c,如果不满足自己的条件,学生A就会向老师告状,在这个班级里面泰迪熊的编号是1,班长的编号是n,班长想和泰迪熊的糖果相差最大,问:在满足m个学生的要求后,班长与泰迪熊的糖果相差最大是多少? 解题思路: 差分约束系统,|Xa-Xb| <= c,我们假设Xa小于Xb,把糖果的最大差当成边权,因为要…
题目链接: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>…
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…
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 loved candies very much and ofte…