# BZOJ 1927: [费用流]

147人阅读 评论(0)

#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);
for (int i = 0; i < n; i++) {
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;
}
2
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：30326次
• 积分：2297
• 等级：
• 排名：第18835名
• 原创：185篇
• 转载：0篇
• 译文：0篇
• 评论：0条
友情链接
阅读排行