A point belongs to a triangle if it lies inside the triangle or on one of its sides. Two triangles are disjoint if there is no point on the plane that belongs to both triangles.

You are given nn points on the plane. No two points coincide and no three points are collinear.

Find the number of different ways to choose two disjoint triangles with vertices in the given points. Two ways which differ only in order of triangles or in order of vertices inside triangles are considered equal.

Input

The first line of the input contains an integer nn (6≤n≤20006≤n≤2000) – the number of points.

Each of the next nn lines contains two integers xixi and yiyi (|xi|,|yi|≤109|xi|,|yi|≤109) – the coordinates of a point.

No two points coincide and no three points are collinear.

Output

Print one integer – the number of ways to choose two disjoint triangles.

Examples

Input
6
1 1
2 2
4 6
4 5
7 2
5 3
Output
6
Input
7
0 -1000000000
-5 -5
5 -5
-5 0
5 0
-2 2
2 2
Output
21

题意:现在有N个点,满足没有三点共线,问有对少对三角形,满足没有公共部分。

思路:如果两个三角形A,B不相交,则有两种方式满足:A选择一个点a,B选择一个点b,三角形AB被直线ab隔开。那么我们枚举直线,然后直线两侧的点数分别是x,y,则其贡献是C(x,2)*C(y,2)*2,*2是因为有a可以和x部分组合,也可以和y部分组合,但最后要/2,因为没对三角形有两种直线满足。

具体的,我们用到了atan2(y1-y2,x1-x2),在一二象限为正,三四象限为负。

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
using namespace std;
const double pi=acos(-1.0);
const int maxn=;
pdd a[maxn]; double w[maxn];
int main()
{
int N; ll ans=;
scanf("%d",&N);
rep(i,,N) scanf("%lf%lf",&a[i].F,&a[i].S);
rep(i,,N){
int tot=;
rep(j,,N) if(j!=i) w[++tot]=atan2(a[j].S-a[i].S,a[j].F-a[i].F); //纵坐标在前,横在后
sort(w+,w++tot);
for(int j=,k=;j<=tot&&w[j]<=;j++){
while(k<=tot&&w[k]-w[j]<pi) k++;
ans+=(ll)(k-j-)*(k-j-)/*(tot-k+j)*(tot-k+j-)/;
}
}
printf("%I64d\n",ans);
return ;
}

CodeForces - 1025F:Disjoint Triangles (几何)的更多相关文章

  1. [CodeForces]CodeForces - 1025F Disjoint Triangles

    题意: 给出平面上n个点,问能在其中选出6个点,组成两个三角形,使得其互不相交 问有多少种选法 大致思路  考虑枚举一条直线,将所有得点分为左右两部分,其中有两个点在直线上, 以这两个点为顶点,分别统 ...

  2. Codeforces 15 E. Triangles

    http://codeforces.com/problemset/problem/15/E 题意: 从H点走下去,再走回H点,不能走重复路径,且路径不能把黑色三角形包围的方案数 中间的黑色三角形把整张 ...

  3. Codeforces 793C - Mice problem(几何)

    题目链接:http://codeforces.com/problemset/problem/793/C 题目大意:给你一个捕鼠器坐标,和各个老鼠的的坐标以及相应坐标的移动速度,问你是否存在一个时间点可 ...

  4. CodeForces - 13D :Triangles(向量法:问多少个蓝点三角形内部无红点)

    Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three ...

  5. Codeforces - 77B - Falling Anvils - 几何概型

    https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...

  6. 【codeforces 229C】Triangles

    [题目链接]:http://codeforces.com/problemset/problem/229/C [题意] 给你一张完全图; 然后1个人从中选择m条边; 然后另外一个人从中选择剩余的n*(n ...

  7. Codeforces 553C Love Triangles(图论)

    Solution: 比较好的图论的题. 要做这一题,首先要分析love关系和hate关系中,love关系具有传递性.更关键的一点,hate关系是不能成奇环的. 看到没有奇环很自然想到二分图的特性. 那 ...

  8. codeforces 659D . Bicycle Race 几何

    题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...

  9. [CF1025F]Disjoint Triangles[极角排序+组合计数]

    题意 平面上有 \(n\) 个点,选出六个点构成两个三角形,问有多少种构造方式使得两个三角形没有交集. \(n\leq 2000\) 分析 枚举连接两个三角形的两个顶点,同时能够将两个三角形划分在直线 ...

随机推荐

  1. Python基础(14)_python模块之configparser模块、suprocess

    9.configparser模块 模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 常见的软件格式文档格式如下: [D ...

  2. MYSQL:基础—主键

    MYSQL:基础—主键 1.什么是主键 表中的每一行都应该具有可以唯一标识自己的一列(或一组列).而这个承担标识作用的列称为主键. 如果没有主键,数据的管理将会十分混乱.比如会存在多条一模一样的记录, ...

  3. Centos6.6安装mysql记录

    一.环境介绍: 系统:Cerntos6.6 Mysql版本:mysql-5.6.34 二.安装操作: 1.卸载旧版本: rpm -qa |grep mysql mysql-server-5.1.73- ...

  4. Centos(Yum源更改)

    第一步:备份你的原镜像文件,以免出错后可以恢复. [root@openstack yum.repos.d]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum. ...

  5. 机器学习算法之:KNN

    基于实例的学习方法中,最近邻法和局部加权回归法用于逼近实值或离散目标函数,基于案例的推理已经被应用到很多任务中,比如,在咨询台上存储和复用过去的经验:根据以前的法律案件进行推理:通过复用以前求解的问题 ...

  6. 管道和xargs的区别

    1.概念 管道:将前一个命令的标准输出作为下一个命令的标准输入. xargs:将标准输入传递给下一个命令,作为其参数.(和管道连用)2.区别 2.区别 1:ls|cat是将ls的结果作为一个文件fil ...

  7. h => h(App)解析

    在创建Vue实例时经常看见render: h => h(App)的语句,现做出如下解析: h即为createElement,将h作为createElement的别名是Vue生态系统的通用管理,也 ...

  8. linux下的cacti安装(centos7)

    1 cacti运行环境准备 cacti需要php+apache+mysql+snmp+RRDTool,以及cacti本身.cacti本体是用php开发的网站,通过snmp对远端设备信息进行采集.apa ...

  9. java string 细节原理分析(2016.5)

    看到了以前2016.5月学习java写的笔记,这里放在一起. String实现的细节原理分析 一.jdk源码中String 的实现 public final class String implemen ...

  10. hadoop 指定 key value分隔符

    原文:http://wingmzy.iteye.com/blog/1260570 hadoop中的map-reduce是处理<key,value>这样的键值对,故指定<key,val ...