UVALive 4650 (平面几何)

题目链接:点击打开链接

题意:给出n个点,每个点有点权,要画两个圆,每个圆圈中某些点(两个圆圈中

的点不能相交),两个圆圈中的点求和再相乘求最大值。有个很关键的条件是三点不

共线。

相当于一条直线分成两堆点(两侧),使得两侧和的乘积最大。直接枚举两个点定下

一条直线,那么直线上的两个点有四种情况,同侧两种异侧两种。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define maxn 211

struct point {
    double x,y;
    point() {}
    point(double x,double y):x(x),y(y) {}
    point operator - ( point a ) {
        return point(x-a.x, y-a.y);
    }
}p[maxn];
long long w[maxn];
int n;

double cross (point a, point b) {
    return (a.x*b.y - a.y*b.x);
}

bool left (point p, point a, point b) {
    point c = b-a, d = p-a;
    return cross (c, d) > 0;
}

int main () {
    while (scanf ("%d", &n) == 1 && n) {
        for (int i = 1; i <= n; i++) {
            scanf ("%lld%lf%lf", &w[i], &p[i].x, &p[i].y);
        }
        long long ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i+1; j <= n; j++) {
                long long sum1 = 0, sum2 = 0;
                for (int k = 1; k <= n; k++) if (k != i && k != j) {
                    if (left (p[k], p[i], p[j]))
                        sum1 += w[k];
                    else
                        sum2 += w[k];
                }
                ans = max (ans, (sum1+w[i]+w[j])*sum2);
                ans = max (ans, sum1*(sum2+w[i]+w[j]));
                ans = max (ans, (sum1+w[i])*(sum2+w[j]));
                ans = max (ans, (sum1+w[j])*(sum2+w[i]));
            }
        }
        printf ("%lld\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值