【poj3159】 Candies】的更多相关文章

http://poj.org/problem?id=3159 (题目链接) 题意 有n个小朋友,班长要给每个小朋友发糖果.m种限制条件,小朋友A不允许小朋友B比自己多C个糖果.问第n个小朋友最多比第1个小朋友多多少糖果. Solution 原来这就是所谓的差分约束..浅显易懂的博客,超详细的博客. 总结一下: >=,求最小值,做最长路: <=,求最大值,做最短路. 可能会觉得很奇怪,用线性规划的角度解释吧.其实我们需要求的就是(n)-(1)<=x或者(n)-(1)>=x,要保证满足…
不多说了.就是裸的模版题. 贴代码: <span style="font-family:KaiTi_GB2312;font-size:18px;">#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 30500 #define M 200000 #define…
题意:有一些人, 给n个人派糖果,给出m组约束,每组约束包含A,B,c 三个数, 意思是A的糖果数比B少的个数不多于c,即B的糖果数 - A的糖果数<= c . 最后求n 比 1 最多多多少糖果. n<=30000 m<=150000 思路:显然差分约束系统 dis[a]-dis[b]<=c 即为b->a连长为c的边 跑SPFA+stack即可,用队列会超时 ..]of longint; head,next,vet,len:..]of longint; inq:..]of b…
题目大意 有 \(n\) 个人排成一个圈,你有 \(k\) 颗糖,你要从第 \(l\) 个人开始发糖,直到第 \(r\) 个人拿走最后一颗糖.注意这 \(n\) 个人拍成了一个圈,所以第 \(n\) 个人拿完后会轮到第 \(1\) 个人拿.第 \(i\) 个人每次拿走的糖的数量是 \(a_i\)(由你决定).如果第 \(r\) 个人要拿两个糖且只剩下一颗糖,那么他就只会拿走这一颗.问你最多能让多少个人每次拿两颗糖. \(n,k\leq {10}^{11}\) 题解 分 \(n\) 小和 \(n\…
Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from the K-th child, who tells all the oth…
HackerRank - candies [贪心] Description Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the children sit in a line (their positions are fixed), and each of them has a rating score according to his or he…
[题目链接] 点击打开链接 [算法] 差分约束系统 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #in…
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at first you don't succeed- SB题,就是注意一下特判就好了,然后我一开始wa了三次... #include<bits/stdc++.h> using namespace std; int read(){ int ans=0,w=1;char c=getchar(); while(!…
不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大部分题用Dij+队列优化都能解决..但有负权边不行哦. Bellman-Ford:反复对边集E中的每条边进行松弛操作. 求含负权图(有负环输出错误提示)的单源最短路径,效率很低,至于对多余松弛的优化就是设置个标记,还是很慢,不如写SPFA. 判断负环:在每次松弛时把每条边都更新一下,若在n-1次松弛…
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies…