【BZOJ】1132: [POI2008]Tro
2015-11-22 13:16
495 查看
题意
给\(n(1 \le n \le 3000)\)个点,求所有三角形的面积和。分析
首先枚举一个点,发现把其它点按照关于这个点的极角排序后第\(i\)个点关于前面\(1\)到\(i-1\)的点组成的三角形的面积之和可以用前缀和和单调性来求出(因为有正负面积之分,而正负具有单调性)。题解
所以我们维护枚举第一个点然后将其它点按照关于这个点为原点的极角排序。然后从左往右扫,计算第\(i\)个点和前\(i-1\)个点的正向面积之和和负向面积之和(叉积来求)。极角排序的\(O(n^2logn)\)常数超大(doge).
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int getint() { int x=0, c=getchar(); for(; c<48||c>57; c=getchar()); for(; c>47&&c<58; x=x*10+c-48, c=getchar()); return x; } const int N=3005; struct ip { int x, y; double ang; void init(int _x, int _y) { x=_x; y=_y; ang=atan2(y, x); } void read() { x=getint(); y=getint(); } }a , p ; bool cmp(const ip &a, const ip &b) { return a.ang<b.ang; } int sumx , sumy ; int main() { int n=getint(); for(int i=1; i<=n; ++i) { p[i].read(); } ll ans=0; for(int i=1; i<=n; ++i) { int tot=0; for(int j=1; j<=n; ++j) { if(p[i].x!=p[j].x || p[i].y!=p[j].y) { a[++tot].init(p[j].x-p[i].x, p[j].y-p[i].y); } } sort(a+1, a+1+tot, cmp); int pos=1; for(int j=1; j<=tot; ++j) { for(; pos<j && a[j].x*a[pos].y>a[j].y*a[pos].x; ++pos); ans+=(ll)a[j].y*(sumx[j-1]-sumx[pos-1])-(ll)a[j].x*(sumy[j-1]-sumy[pos-1]); ans+=(ll)a[j].x*sumy[pos-1]-(ll)a[j].y*sumx[pos-1]; sumx[j]=sumx[j-1]+a[j].x; sumy[j]=sumy[j-1]+a[j].y; } } ans/=3; ans*=10; ans/=2; printf("%lld.%lld\n", ans/10, ans%10); return 0; }
相关文章推荐
- Android学习手记(2) Activity生命周期
- BZOJ 3156: 防御准备( dp + 斜率优化 )
- mybatis和ibatis控制台打印sql语句方法
- 【BZOJ】1124: [POI2008]枪战Maf
- 【SSH项目实战】国税协同平台-27.分页对象应用&抽取pageNavigator
- 115 Distinct Subsequences
- Snackbar 的使用
- 寄存器
- IOS影响Animiation动画的事件
- 在VS2015配置OpenGL和谢尔宾斯基三角(Sierpinski triangle)例子
- XDU-1107 Too Simple (DP)
- 【BZOJ】1119: [POI2009]SLO
- 超级坦克大战1990 - 坦克大战超难版
- 本计算机上sql sever服务启动后又关闭的问题
- 关于Fragment的使用与Androikd sdk版本之间的东东
- 【BZOJ】1110: [POI2007]砝码Odw
- Ubuntu14.04下安装Hadoop2.4.0 (单机模式)
- 关于博客封面的提取与处理
- Html5之FileReader接口
- 欢迎使用CSDN-markdown编辑器