bzoj 1132 POI2008 Tro

    大水题=_=,可我想复杂了……

    很裸的暴力,就是加了个小优化……

    叉积求面积 :abs(xi*yj - yi*xj) 所以去掉绝对值,把 xi 和 xj 提出来就可以求和了

    去绝对值加个极角排序,每次把最左边的点当成原点,然后剩下的排序,接着枚举第二个点,求叉积之和……

    坐标都是整数,用long long,最后再除2

    上代码:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#define N 3010
using namespace std;

struct sss
{
    long long x, y;
}dian[N], now, zan[N];
int n;
long long ans = 0;

long long chaji(sss x, sss y)
{
    return (x.x-now.x)*(y.y-now.y) - (x.y-now.y)*(y.x-now.x);
}

bool cmp1(sss x, sss y) { return x.x == y.x ? x.y < y.y : x.x < y.x; }
bool cmp2(sss x, sss y ){ return chaji(x, y) > 0; }

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%lld%lld", &dian[i].x, &dian[i].y);
    sort(dian+1, dian+1+n, cmp1);
    for (int i = 1; i <= n-2; ++i)
    {
        now = dian[i];
        long long ty = 0, tx = 0;
        for (int j = i+1; j <= n; ++j) zan[j] = dian[j];
        sort(zan+i+1, zan+1+n, cmp2);
        for (int j = i+1; j <= n; ++j)
        {
            ty += zan[j].y-now.y;
            tx += zan[j].x-now.x;
        }
        for (int j = i+1; j <= n-1; ++j)
        {
            ty -= zan[j].y-now.y; tx -= zan[j].x-now.x;
            ans += (zan[j].x-now.x)*ty - (zan[j].y-now.y)*tx;
        }
    }
    if (ans % 2) printf("%lld.5\n", ans/2);
    else printf("%lld.0\n", ans/2);
}

 

posted @ 2014-10-04 16:57  handsomeJian  阅读(324)  评论(0编辑  收藏  举报