BZOJ 差分约束: 我是谁,差分约束是啥,这是哪 太真实了= = 插个广告:这里有差分约束详解. 记\(r_i\)为第\(i\)行整体加了多少的权值,\(c_i\)为第\(i\)列整体加了多少权值,那么限制\((i,j),k\)就是\(r_i+c_j=k\). 这就是差分约束裸题了.\(r_i+c_j=k\Rightarrow r_i-(-c_j)\leq k\ \&\&\ -c_j-r_i\leq -k\). 注意形式是\(x_j-x_i\leq w\)=v= 建边跑最短路判负环即可.…
King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11946   Accepted: 4365 Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound kin…
题意:一个账本记录了N个月以来的收入情况,现在有一个侦探员不同时间偷看到M段时间内的总收入,问这个账本是否为假账. 解法:带权并查集+前缀和.   判断账本真假是通过之前可算到的答案与当前读入的值是否相同来完成.那么就是只有知道新读入的区间2端的(在相同区域内的!!)前缀和才可以判断,也就是这2个端点之前被纳入了相同的区域内才可以判断.于是,我们就可以想到并查集了.(( ′◔ ‸◔`) 真的么......)   假设已知x~y月的总收入为d,那么s[y]-s[x-1]=d.一般前缀和是算上自己的…
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4500 题解: 从行向列建边,代表一个格子a[i][j],对每个顶点的所有操作可以合并在一起用sum[xi]表示, 那么题目相当于是要求sum[xi]+sum[xj]==a[xi][xj]: 等价于:sum[xj]-(-sum[xi])==a[xi][xj] 等价于:sum[xj]-sum'[xi]<=a[xi][xj] && sum[xj]-sum'[xi]>=a[x…
第一次看这个题目,完全不知道怎么做,看起来又像是可以建个图进行搜索,但题目条件就给了你几个不等式,这是怎么个做法...之后google了下才知道还有个差分约束这样的东西,能够把不等式化成图,要求某个点在满足所有不等式的情况下的最大取值,只需对建好的图进行一次最短路即可 不过要使得a b 点满足这样 a<=b+k这种不等式,还得对题目所给的不等式进行下改装 原不等式无非就是 输入个 si ni,使得存在 A(si)+...A(si+ni)<k 或者 >k,我们新定义一个s[],s[i]代表…
传送门 差分约束系统..找负环用spfa就行 ——代码 #include <cstdio> #include <cstring> #include <iostream> #define N 100001 int n, m, cnt; ], val[N << ], next[N << ], dis[N]; bool vis[N]; inline int read() { , f = ; char ch = getchar(); ; ) + (x &…
Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; const int N=300000+3; const int INF=-2333233; queue<int>Q; int d[N],inq[N],times[N]; int head[N],to[N<<1],val[N<<1],nex[N<<1]; int cn…
这道题一开始以为是平衡树结果发现复杂度过不去,然后发现我们一直合并而且只是记录到最低的距离,那么就是带权并查集了,带权并查集的权一般是到根的距离,因为不算根要好打,不过还有一些其他的,具体的具体打. #include <cstdio> #include <cstring> ; int h[N],f[N],size[N]; ]; inline int find(int x){ if(f[x]==x)return x; int temp=f[x];f[x]=find(f[x]); if…
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42366 Accepted: 15560 传送门 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14791   Accepted: 5226 Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound kin…