码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj 1132 POI2008 Tro

时间:2014-10-04 19:53:47      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   for   sp   div   c   

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

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

    叉积求面积 :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);
}

 

bzoj 1132 POI2008 Tro

标签:style   blog   color   io   os   for   sp   div   c   

原文地址:http://www.cnblogs.com/handsomeJian/p/4006136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!