poj3159 Candies 这题实质为裸的差分约束. 先看最短路模型:若d[v] >= d[u] + w, 则连边u->v,之后就变成了d[v] <= d[u] + w , 即d[v] – d[u] <= w. 再看题目给出的关系:b比a多的糖果数目不超过c个,即d[b] – d[a] <= c ,正好与上面模型一样, 所以连边a->b,最后用dij+heap求最短路就行啦. ps:我用vector一直TLE,后来改用链式前向星才过了orz... #include&…
Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 40407   Accepted: 11367 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…
分析:设每个人的糖果数量是a[i] 最终就是求a[n]-a[1]的最大值 然后给出m个关系 u,v,c 表示a[u]+c>=a[v] 就是a[v]-a[u]<=c 所以对于这种情况,按照u,v,c建单向边,一条从1到n的路径就是一个关于1和n的推广不等式a[n]-a[1]<=k(k为这条路的权) 所以找到所有不等式中最小k,就是求1到n的最短路,这就是差分约束 然后上代码: #include<cstdio> #include<cstring> #include&l…
题意 编号为 1..N 的人, 每人有一个数; 需要满足 dj - di <= c 求1号的数与N号的数的最大差值.(略坑: 1 一定要比 N 大的...difference...不是"差别", 而是"做差"....) 思路 差分约束 差分约束顾名思义就是以"差值"作为约束条件的规划问题. 这个"差值"的特点使得这个问题可以转化为最短路问题(或最长路?) 由于SFPA(或Dijkstra)中的松弛操作: d[v] <…
题面 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 compare…
题意:n个人,m个信息,每行的信息是3个数字,A,B,C,表示B比A多出来的糖果不超过C个,问你,n号人最多比1号人多几个糖果 解题关键:差分约束系统转化为最短路,B-A>=C,建有向边即可,与dijkstra中的d[v]>=d[u]+C相同,即可求解. 最小值用最长路,最大值用最短路. 技巧:有一个超级源点向所有点连边,来固定每个点的约束. #include<cstdio> #include<cstring> #include<algorithm> #in…
Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 22177   Accepted: 5936 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://www.cnblogs.com/fraud/          ——by fraud Candies Time Limit: 1500MS   Memory Limit: 131072K Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’…
题目链接:http://poj.org/problem?id=3159 Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 33576   Accepted: 9422 Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought th…
http://poj.org/problem?id=3159 题意: flymouse是幼稚园班上的班长,一天老师给小朋友们买了一堆的糖果,由flymouse来分发,在班上,flymouse和snoopy是死对头,两人势如水火,不能相容,因此fly希望自己分得的糖果数尽量多于snoopy,而对于其他小朋友而言,则只希望自己得到的糖果不少于班上某某其他人就行了. 比如A小朋友强烈希望自己的糖果数不能少于B小朋友m个,即B- A<=m,A,B分别为A.B小朋友的分得的糖果数.这样给出若干组这样的条件…