bzoj 1132 POI2008 Tro

时间:2023-09-07 19:20:02

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

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

叉积求面积 :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 = ; 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) > ; } int main()
{
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%lld%lld", &dian[i].x, &dian[i].y);
sort(dian+, dian++n, cmp1);
for (int i = ; i <= n-; ++i)
{
now = dian[i];
long long ty = , tx = ;
for (int j = i+; j <= n; ++j) zan[j] = dian[j];
sort(zan+i+, zan++n, cmp2);
for (int j = i+; j <= n; ++j)
{
ty += zan[j].y-now.y;
tx += zan[j].x-now.x;
}
for (int j = i+; j <= n-; ++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 % ) printf("%lld.5\n", ans/);
else printf("%lld.0\n", ans/);
}