UVALive 4650 (平面几何)

来源:互联网 发布:服务器 ftp端口号 编辑:程序博客网 时间:2024/04/29 16:00

题目链接:点击打开链接

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

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

共线。

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

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

#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <cmath>using namespace std;#define maxn 211struct 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;}


0 0