费用流的建模。。。
想到从一个星球瞬间转移到另一个星球和最初就转移到那个星球的意义是等价的。
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define N 2010
using namespace std;
inline char get(void) {
static char buf[1000000], *p1 = buf, *p2 = buf;
if (p1 == p2) {
p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
if (p1 == p2) return EOF;
}
return *p1++;
}
inline void read(int &x) {
x = 0; char c = get(); int sign = 1;
for (; c < '0' || c > '9'; c = get()) if(c == '-') sign = 0;
for (; c >= '0' && c <= '9'; x = (x << 1) + (x << 3) + c - '0', c = get());
x = sign ? x : -x;
}
int x0, y0, ans = 0, X1, X2, Y, n, cnt, sum;
struct point {
int x, y, w;
point(int _x = 0, int _y = 0, int _w = 0) :x(_x), y(_y), w(_w) {}
};
point a[N << 1];
bool cmp(const point &a, const point &b) {
if (a.x == x0 && a.y == y0) return true;
if (b.x == x0 && b.y == y0) return false;
int adx = a.x - x0, bdx = b.x - x0, ady = a.y - y0, bdy = b.y - y0;
if (adx * bdx < 0) return adx > bdx;
return ((ady * 1.0) / adx) < ((bdy * 1.0) / bdx);
}
int main(void) {
freopen("1.in", "r", stdin);
read(n);
for (int i = 0; i < n; i++) {
read(X1); read(X2); read(Y);
if (X1 > X2) swap(X1, X2);
a[cnt++] = point(X1, Y, X2 - X1);
a[cnt++] = point(X2, Y, X1 - X2);
}
for (int i = 0; i < cnt; i++) {
x0 = a[i].x; y0 = a[i].y;
sort(a, a + cnt, cmp); sum = 0;
if (a[0].w > a[1].w) swap(a[0], a[1]);
for (int j = 1; j < cnt; j++) ans = max(ans, sum += a[j].w);
}
cout << ans << endl;
return 0;
}