bzoj1132

来源:互联网 发布:php文件输出乱码 编辑:程序博客网 时间:2024/06/06 03:50

poi~~~

叉积  极角排序(雾 %%%

a x b + a x c = a x (b + c)

注意符号  那么这道题就easy 了

n2预处理所有向量

枚举每一个点作为顶点的情况

极角排序

然后用个前缀和


n^2logn


卡精度sxbk。。



#include <cmath>#include <cstdio>#include <algorithm>#define LL long longusing namespace std;int n;LL ans;struct point {int x,y;double angle;int lx,ly;bool operator < (const point &b)const {if(x == b.x) return y < b.y;return x < b.x;}point operator - (point b) {point t;t.x = x - b.x;t.y = y - b.y;return t;}point operator + (point b) {point t;t.x = x + b.x;t.y = y + b.y;return t;}}p[3010],v[3010],sum[3010];int cnt;bool cmp (const point &a,const point &b) {if(!(a.lx == b.lx && a.ly == b.ly)) {if(a.lx == b.lx)return a.ly < b.ly;return a.lx < b.lx;}else return a.angle < b.angle;}int read_int () {char c = getchar();int re = 0;for(;c > '9' || c < '0';c = getchar());for(;c >= '0' && c <= '9';c = getchar())re = re * 10 + c - '0';return re;}LL cross (point a,point b) {return (LL)a.x * b.y - (LL)a.y * b.x;}int main () {n = read_int();for(int i = 1;i <= n;++i) {p[i].x = read_int();p[i].y = read_int();}sort(p + 1,p + 1 + n);sum[0].x = sum[0].y = 0;for(int i = 1;i <= n - 1;++i) {cnt = 0;for(int j = i + 1;j <= n;++j) {v[++cnt] = p[j] - p[i];v[cnt].lx = p[i].x;v[cnt].ly = p[i].y;v[cnt].angle = atan2(v[cnt].y,v[cnt].x);}sort(v + 1,v + 1 + cnt,cmp);for(int j = 1;j <= cnt;++j)sum[j] = sum[j - 1] + v[j];for(int j = cnt;j > 1;--j) {ans += (LL)abs(cross(sum[j - 1],v[j]));}}    if(ans&1)printf("%lld.5\n",ans>>1);    else printf("%lld.0\n",ans>>1);}


0 0
原创粉丝点击