BZOJ 1927: [费用流]

费用流的建模。。。
想到从一个星球瞬间转移到另一个星球和最初就转移到那个星球的意义是等价的。

#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;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值