先考虑如何求出任意两数的最大差值和最小差值,直接差分约束建图跑floyd求最短路和最长路即可然后枚举i和j,考虑dA+dB和di+dj的关系,分两种情况移项,转化成dA-di和dj-dB的关系或dA-dj和di-dB的关系(只要有一个关系确定即确定)即可考虑(由于不等式都是两个变量,因此一定无法形成dA-dj和dB-di的固定关系) 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,x,y,c1,c2,c3,mx[105][105…
[BZOJ1077]天平(差分约束) 题面 BZOJ 洛谷 题解 利用矩阵可以很容易得到两个点之间的最大差和最小差,再利用这个信息判断即可.差分约束用\(Floyd\)计算.时间复杂度\(O(n^3)\). #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAX 55 int dmn[MAX][MAX],dmx[MAX][MAX]; int n,A,B,…
Description Farmer John has a balance for weighing the cows. He also has a set of N (1 <= N <= 1000) weights with known masses (all of which fit in 31 bits) for use on one side of the balance. He places a cow on one side of the balance and then adds…