题目大意:
  平面直角坐标系上有n个点,问以这n个点为顶点的不同的三角形的面积和是多少?

思路:
  很容易想到一个O(n^3)的暴力,枚举三个点,用海龙公式求一下面积和即可,这样做是40分。
  标算的复杂度是O(n^2 log n),
  首先对所有的点按照位置的左右排序,
  按顺序枚举每一个点i,并将其作为三角形的一个顶点。
  对于顺序在i后面的点关于点i极角排序,并按照极角序枚举每一个点j。
  三角形面积的两倍我们可以用叉积来求。
  为了不枚举第三个顶点,我们可以算一下后缀和。
  这题会爆double,由于小数部分要么是.0要么是.5,我们可以用long long来存一下,最后特判一下奇数偶数即可。

 #include<cstdio>
#include<cctype>
#include<algorithm>
typedef long long int64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=;
struct Point {
int x,y;
Point operator - (const Point &another) const {
return (Point){x-another.x,y-another.y};
}
int64 operator * (const Point &another) const {
return (int64)x*another.y-(int64)y*another.x;
}
};
Point p[N],t[N];
inline bool cmp1(const Point &a,const Point &b) {
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
}
inline bool cmp2(const Point &a,const Point &b) {
return a*b>;
}
int main() {
int n=getint();
for(register int i=;i<n;i++) {
p[i]=(Point){getint(),getint()};
}
std::sort(&p[],&p[n],cmp1);
int64 ans=;
for(register int i=;i<n;i++) {
int cnt=;
for(register int j=i+;j<n;j++) {
t[++cnt]=p[j]-p[i];
}
std::sort(&t[],&t[cnt+],cmp2);
Point sum=(Point){,};
for(register int j=cnt;j;j--) {
ans+=sum*t[j];
sum=sum-t[j];
}
}
printf("%lld.%c\n",ans>>,(ans&)?'':'');
return ;
}

[POI2008]Triangles的更多相关文章

  1. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  2. [BZOJ1112][POI2008]砖块Klo

    [BZOJ1112][POI2008]砖块Klo 试题描述 N柱砖,希望有连续K柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出一块砖,放到另 ...

  3. [bzoj1122][POI2008]账本BBB

    1122: [POI2008]账本BBB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 402  Solved: 202[Submit][Status ...

  4. BZOJ 1113: [Poi2008]海报PLA

    1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1025  Solved: 679[Submit][Statu ...

  5. BZOJ 1116: [POI2008]CLO

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 922  Solved: 514[Submit][Status][ ...

  6. BZOJ 1112: [POI2008]砖块Klo

    1112: [POI2008]砖块Klo Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1736  Solved: 606[Submit][Statu ...

  7. BZOJ 1124: [POI2008]枪战Maf

    1124: [POI2008]枪战Maf Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 617  Solved: 236[Submit][Status ...

  8. BZOJ 1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1030  Solved: 440[Submit][Status] ...

  9. BZOJ 1121: [POI2008]激光发射器SZK

    1121: [POI2008]激光发射器SZK Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 792  Solved: 653[Submit][Sta ...

随机推荐

  1. 简谈const限定符

    const修饰的数据类型是常量类型,常量类型的对象和变量在定义初始化后是不能被更新的.其实只用记住这一个概念,就可以明白const操作对象的方法. 1)定义const常量 最简单的: const in ...

  2. [device tree] How to decompile a compiled .dtb (device tree blog) into .dts (device tree source).

    $ ./out/target/product/project_name/obj/KERNEL_OBJ/scripts/dtc/dtc -I dtb -O dts -o decompiled.dts ~ ...

  3. java===java基础学习(1)---数据类型,运算,变量,常量

    今天起开始了java的学习之路,主要学习了数据类型和运算,变量,常量.基本和python有很多相通的地方,所以看起来很容易上手.下面是学习笔记! package testbotoo; public c ...

  4. CentOS在ssh下远程重装系统

    CentOS在ssh下远程重装系统 http://www.zxsdw.com/index.php/archives/913/ 国外VPS服务器一般都有控制面板,有很多种系统可自行安装,但国内有些IDC ...

  5. An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceModel.dll

    异常“ An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceMo ...

  6. HDU 5117 Fluorescent

    题目链接:HDU-5117 题意为有n盏灯,m个开关,每个开关控制着\( k_{i} \)灯.X为最后亮着的灯的个数,要求出\( E(X^{3} ) * 2^{M} mod (10^9 + 7) \) ...

  7. 【msgpack-python】安装

    1.安装pip:http://blog.iyestin.com/2014/03/15/python-pip-install/ http://www.linuxde.net/2014/05/15576. ...

  8. ReentrantLock 分析

    带着疑问去分析 ReentrantLock是如何实现锁管理的. ReentrantLock是如何实现重入的. ReentrantLock是如何实现公平锁与非公平锁. ReentantLock的公平锁为 ...

  9. Oracle 通用存储过程

    CREATE OR REPLACE PROCEDURE P_Pub_GetList ( StrWhere varchar2, ---查询条件(不带where关键字的查询条件) TableName va ...

  10. Letter Combinations of a Phone Number——简单的回溯算法

    Given a digit string, return all possible letter combinations that the number could represent. A map ...