http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题目大意: 陆逊为了火烧连营七百里,派出了间谍刺探敌情,得之刘备的军营以1~n编号一字排开,第i个大营最多能容纳Ci个士兵.而且通过观察刘备军队的动静,陆逊可以估计到从第i个大营到第j个大营至少有多少士兵.最后,陆逊必须估计出刘备最少有多少士兵,这样他才知道要派多少士兵去烧刘备的大营.为陆逊估计出刘备军队至少有多少士兵.然而,陆逊的估计可能不是很精确,如果不能很精确地估…
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2770 Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeat…
// 差分约束系统// 火烧连营 // n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i-1,i) 权值为 C[i]// 2.S(i-1)-Si<=0 这里 建边(i,i-1) 权值为 0// 3.S(j)-S(i-1)>=k => S(i-1)-Sj<=-k 这里建边 (j,i-1) 权值为 -k// 题目求的事 Sn-S0的最小值 Sn-S0>=m 中符合条件的m…
//差分约束 >=求最长路径 <=求最短路径 结果都一样//spfa#include<stdio.h> #include<string.h> #include<limits.h> #include<queue> using namespace std; #define N 1010 #define M 1010*1010//注意边和点集的数组大小 struct edge { int to,value,next; }; struct edge ed…
有n个营地,每一个营地至多容纳Ci人.给出m个条件:第i到第j个营地之间至少有k人. 问n个营地总共至少有多少人. 此题显然差分约束.要求最小值.则建立x-y>=z方程组,建图求最长路. 用d[i]表示[1,i]个帐篷中一共多少人.依据题意可得到不等关系: 1.0<=d[i]-d[i-1]<=C[i] 2.d[j]-d[i]>=k 此外,我们加入0为附加结点,则0到其它点也要建边. 再求解0为源点的最长路就可以. 我的坑点是,判负环返回0.否则返回d[n]. 而d[n]本身就可能是…
今天刚刚学差分约束系统.利用最短路求解不等式.世界真的好奇妙!感觉不等式漏下几个会导致WA!! #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; ; vector<int>ljb[maxn];//邻接表 int jz[maxn…
Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a general of the Wu Empire. The defeat was due to Liu Be…
Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a general of the Wu Empire. The defeat was due to Liu Be…
区间和一定要联系到前缀和. 这题,把前缀和看作点,从s0到sn: 对于每一个营地i的容量capi,有这么个关系si-si-1<=capi: 对于每一个区间的评估i,j,k,有sj-si-1>=k,即si-1-sj<=k: 接下来就是连边了,对于v<=u+w由u向v连权w的边,超级源向n+1个点连权0的边. 最后跑SPFA,如果出现负环则无解:而有解的话,所求答案就在d[sn]里,不过因为题目的前缀和是非负整数且要求的最少,所以就要让d中所有数都同时加上合适的数得到另一个真正所求的解…
Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a general of the Wu Empire. The defeat was due to Liu Be…