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. LeetCode:二进制求和【67】

    LeetCode:二进制求和[67] 题目描述 给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11" ...

  2. selection createTextRange setSelectionRange

    http://www.cnblogs.com/rainman/archive/2011/02/27/1966482.html http://www.zhangxinxu.com/wordpress/2 ...

  3. PAT 天梯赛 L2-024. 部落 【并查集】

    题目链接 https://www.patest.cn/contests/gplt/L2-024 题意 给出 几个不同的圈子,然后 判断 有哪些人 是属于同一个部落的,或者理解为 ,有哪些人 是有关系的 ...

  4. 大道至简(第五i章)读后感

    大道至简(第五章)读后感 再一次在不想看的情况下读大道至简第五章,一个项目的实现中,“过程”与“工程”是同一个概念吗?答案自然是否定的.“过程”是一个确定的模板,而“工程”是有一个目的的实现在里面. ...

  5. Apache Kudu

    Apache Kudu是由Cloudera开源的存储引擎,可以同时提供低延迟的随机读写和高效的数据分析能力.Kudu支持水平扩展,使用Raft协议进行一致性保证,并且与Cloudera Impala和 ...

  6. iOS_AutoLayout自动布局

    目录: 一.什么是AutoLayout? 二.创建autoLayout的方法 三.VFL语言     一.什么是AutoLayout? Autolayout是一种“自动布局”技术,专门用来布局UI界面 ...

  7. redis memcached MongoDB

    我们现在使用的模式是,对于直接的key value对需缓存的直接用memcached.对于collection类型就使用Redis.对于大数据量的内容性的东西,我们打算尝试用mongoDB.也正在学习 ...

  8. Kafka详解二:如何配置Kafka集群

    问题导读1.Kafka有哪几种配制方法?2.如何启动一个Consumer实例来消费消息? Kafka集群配置比较简单,为了更好的让大家理解,在这里要分别介绍下面三种配置 单节点:一个broker的集群 ...

  9. 运行tomcat,报错:Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??错误

    运行tomcat时,报错: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??错误 原因分析: 这是因为之前已开启了一 ...

  10. QT5中如何使用QFtp类

    QT5中如何使用QFtp类 http://2662597.blog.51cto.com/2652597/1279806 由于QT5对QML的支持有很大的改进,所以打算将原来基于QT4的程序移植到QT5 ...