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
  1. 6
    1 1
    2 2
    4 6
    4 5
    7 2
    5 3
Output
  1. 6
Input
  1. 7
    0 -1000000000
    -5 -5
    5 -5
    -5 0
    5 0
    -2 2
    2 2
Output
  1. 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),在一二象限为正,三四象限为负。

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define pii pair<int,int>
  4. #define pdd pair<double,double>
  5. #define rep(i,a,b) for(int i=a;i<=b;i++)
  6. #define F first
  7. #define S second
  8. using namespace std;
  9. const double pi=acos(-1.0);
  10. const int maxn=;
  11. pdd a[maxn]; double w[maxn];
  12. int main()
  13. {
  14. int N; ll ans=;
  15. scanf("%d",&N);
  16. rep(i,,N) scanf("%lf%lf",&a[i].F,&a[i].S);
  17. rep(i,,N){
  18. int tot=;
  19. rep(j,,N) if(j!=i) w[++tot]=atan2(a[j].S-a[i].S,a[j].F-a[i].F); //纵坐标在前,横在后
  20. sort(w+,w++tot);
  21. for(int j=,k=;j<=tot&&w[j]<=;j++){
  22. while(k<=tot&&w[k]-w[j]<pi) k++;
  23. ans+=(ll)(k-j-)*(k-j-)/*(tot-k+j)*(tot-k+j-)/;
  24. }
  25. }
  26. printf("%I64d\n",ans);
  27. return ;
  28. }

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. VS 无法调试 IIS

    用附加的方式断点无效时.   解决方案: 一.VS设置的  .Net版本 与 IIS应用程序池的版本  不一致.   操作步骤: 1. 在VS-> 项目属性, 配置 自定义Web服务器 , 这里 ...

  2. docker commit

    不能将挂载的外部volume修改的内容一块commit

  3. focus + select

    focus使光标定位到目标节点之后 select选中光标所在位置的全部内容

  4. 每天一个Linux命令(38)top命令

     top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.       (1)用法:       用法:  top  [参数] top是 ...

  5. $Java正则表达式基础整理

    (一)正则表达式及语法简介 String类使用正则表达式的几个方法: 正则表达式支持的合法字符: 特殊字符: 预定义字符: 方括号表达式: 圆括号表达式:用于将多个表达式组成一个子表达式,可以使用或运 ...

  6. hadoop05---进程线程

    J2ee是一种规范,tomcat.jboss.weblogic就是实现.JMS是一种规范,ActiveMQ是实现. .1.1. 进程介绍.线程介绍 进程:它是内存中的一段独立的内存空间. 线程:是在进 ...

  7. git 使用教程 --基础二

    一:分支学习: branch称为分支,默认仅有一个名为master的分支.一般开发新功能流程为:开发新功能时会在分支dev上进行,开发完毕后再合并到master分支. 分支的作用: 创建分支:(创建分 ...

  8. Python编程-多线程

    一.python并发编程之多线程 1.threading模块 multiprocess模块的完全模仿了threading模块的接口,二者在使用层面,有很大的相似性,因而不再详细介绍 1.1 开启线程的 ...

  9. web框架详解之三Modal

    一.Modal操作之创建表,添加数据 1. 配置Django中settings的设置连接mysql数据库,然后在mysql数据库中创建库 2. 在models中创建表.继承Model 3. 在sett ...

  10. Linux bridge

    CentOS bridge 配置: 1.创建br0配置文件  touch /etc/sysconfig/network-scripts/ifcfg-br0 2.修改bro配置文件 vi /etc/sy ...