BZOJ 1132 [POI2008]Tro(极角排序)
【题目链接】 http://www.lydsy.com/JudgeOnline/problem.php?id=1132
【题目大意】
平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和(N<=3000)
【题解】
我们发现直接枚举三个点计算会造成很大部分的叉积重复被计算,
因此我们枚举i,计算pj和pi点差的后缀和,我们发现对于固定边ij,
其与后面的枚举量相关贡献就为pj-pi和点差后缀和的叉积。
因此我们针对每个i进行后面数据的极角排序,O(n)计算与i相关的所有答案贡献。
【代码】
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
struct Point{
int x,y; int index;
Point(){} Point(int x1,int y1){x=x1;y=y1;}
Point operator +(const Point &b)const{return Point(x+b.x,y+b.y);}
Point operator -(const Point &b)const{return Point(x-b.x,y-b.y);}
int operator *(const Point &b)const{return x*b.x+y*b.y;} //点积
LL operator ^(const Point &b)const{return (LL)x*b.y-(LL)y*b.x;} //叉积
};
double dist(Point a,Point b){return sqrt((a-b)*(a-b));}
int pos; Point p[3010];
bool cmp(Point a,Point b){
LL tmp=(a-p[pos])^(b-p[pos]);
if(tmp==0)return dist(p[pos],a)<dist(p[pos],b);
else if(tmp<0)return false;
else return true;
}
int n;
int main(){
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}LL ans=pos=0;
sort(p+1,p+n+1,cmp);
for(int i=1;i<=n-2;i++){
p[0].x=p[0].y=0;pos++;
sort(p+i+1,p+n+1,cmp);
for(int j=i+1;j<=n;j++)p[0]=p[0]+(p[j]-p[i]);
for(int j=i+1;j<=n;j++){
p[0]=p[0]-(p[j]-p[i]);
ans+=(p[j]-p[i])^p[0];
}
}if(ans&1)printf("%lld.5\n",ans>>1);
else printf("%lld.0\n",ans>>1);
}return 0;
}
BZOJ 1132 [POI2008]Tro(极角排序)的更多相关文章
- BZOJ.1132.[POI2008]Tro(极角排序)
BZOJ 洛谷 考虑暴力,每次枚举三个点,答案就是\(\frac12\sum_{k<j<i}(i-k)\times(j-k)\). 注意到叉积有分配率,所以固定\(k\),枚举\(i,j\ ...
- bzoj 1132 POI2008 Tro
大水题=_=,可我想复杂了…… 很裸的暴力,就是加了个小优化…… 叉积求面积 :abs(xi*yj - yi*xj) 所以去掉绝对值,把 xi 和 xj 提出来就可以求和了 去绝对值加个极角排序,每次 ...
- bzoj 1132 [POI2008]Tro 几何
[POI2008]Tro Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1796 Solved: 604[Submit][Status][Discu ...
- bzoj 1132: [POI2008]Tro 计算几何
题目大意: 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000 题解 我们看到了n的范围,于是我们就知道这一定不是一个线性算法 所以我们尝试枚举三角形的一个点,那么我们现 ...
- 【刷题】BZOJ 1132 [POI2008]Tro
Description 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000 Input 第一行给出数字N,N在[3,3000] 下面N行给出N个点的坐标,其值在[0,10 ...
- 【BZOJ】1132: [POI2008]Tro
题意 给\(n(1 \le n \le 3000)\)个点,求所有三角形的面积和. 分析 首先枚举一个点,发现把其它点按照关于这个点的极角排序后第\(i\)个点关于前面\(1\)到\(i-1\)的点组 ...
- BZOJ1132: [POI2008]Tro(叉积 排序)
题意 世上最良心题目描述qwq 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000 Sol 直接模拟是$n^3$的. 考虑先枚举一个$i$,那么我们要算的就是$\sum_ ...
- BZOJ1132: [POI2008]Tro
1132: [POI2008]Tro Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 815 Solved: 211[Submit][Status] ...
- bzoj1132[POI2008]Tro 计算几何
1132: [POI2008]Tro Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1722 Solved: 575[Submit][Status] ...
随机推荐
- web_一些常用的线上脚本地址记录(个人使用)
1.jquery <script src="http://code.jquery.com/jquery-1.4.1.min.js"></script> 2. ...
- centos7.2进入单用户模式修改密码
1 - 在启动grub菜单,选择编辑选项启动 2 - 按键盘e键,来进入编辑界面 3 - 找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh 4 - 现在按下 Co ...
- php中使用static方法
<?php class Char{ public static $number = 0; public static $name; function __construct($what){ se ...
- 一个无线通信类投稿的期刊list
转载一个,但是有些期刊的影响因子不是很对,要投的时候还是再到期刊主页上面看一看吧~ 期刊缩写 期刊全名 近年影响因子 P IEEE Proceedings Of The IEEE 3.686 IEEE ...
- 真正的上锁前,为何要调用preempt_disable()来关闭抢占的case【转】
转自:http://blog.csdn.net/kasalyn/article/details/11473885 static inline void raw_spin_lock(raw_spinlo ...
- 项目评审ppt的纲要
1.prd不能模糊,产品的问题全部明确 2.收益在哪里 3.设计体现业务4.怎样保证数据的前后协作5.异常如何处理6.技术解决的痛点7.对外部依赖8.性能指标预期(响应时间)9.
- [New learn]AutoLayout调查基于IB
代码:https://github.com/xufeng79x/AutoLayout-IB 1.简介 Autolayout旨在解决不同高宽度的屏幕下的显示问题,通过增加给控件增加约束来达到不同屏幕间的 ...
- [ python ] 查询数据库生成Excel并发送邮件
开发要求: 由于管理后台导出数据非常缓慢,找程序员解决无果后,自己动手写了一个脚本,每天定时将报表发送给业务部门. 1. 通过条件查询MySQL获取数据 2. 将获取的数据写入到Excel ...
- Leetcode 之Binary Tree Postorder Traversal(45)
层序遍历,使用队列将每层压入,定义两个队列来区分不同的层. vector<vector<int>> levelorderTraversal(TreeNode *root) { ...
- POJ-3268
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13738 Accepted: 6195 ...