BZOJ1132: [POI2008]Tro

鬼畜的BZOJ。。。换个输出就A?!!!
叉积的前缀和方法

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define youhua __attribute__((optimize("O2")))
struct Point
{
    int  x,y;
  youhua  inline friend  int operator *(Point a,Point b)
    {return a.x*b.y-b.x*a.y;}
};
Point Pl;
Point Sort[3001];
youhua inline bool cmp(Point a,Point b)
{return a*b<0;}
Point Line[3001];
youhua int main()
{

    int n;
    scanf("%d\n",&n);
    int i,j,k,tot;
    for(i=1;i<=n;i++)scanf("%d%d",&Line[i].x,&Line[i].y);
    long long x,y,ans=0;
    for(i=1;i<=n;i++)
    {
        tot=0;
        for(j=1;j<=n;j++)
            if(i^j&&((Line[i].y<Line[j].y)||(Line[i].y==Line[j].y&&Line[i].x<Line[j].x)))
                Sort[++tot].x=Line[j].x-Line[i].x,Sort[tot].y=Line[j].y-Line[i].y;
        sort(Sort+1,Sort+1+tot,cmp);
        x=0,y=0;
        for(j=1;j<=tot;j++)
        {
          ans+=y*Sort[j].x-x*Sort[j].y;
          x+=Sort[j].x;
          y+=Sort[j].y;
        }
    }
    printf("%lld.%d\n",ans>>1,ans&1?5:0);
    return 0;
}

你可能感兴趣的:(poi)