CodeForces - 1025F:Disjoint Triangles (几何)
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
6
1 1
2 2
4 6
4 5
7 2
5 3
6
7
0 -1000000000
-5 -5
5 -5
-5 0
5 0
-2 2
2 2
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 (几何)的更多相关文章
- [CodeForces]CodeForces - 1025F Disjoint Triangles
题意: 给出平面上n个点,问能在其中选出6个点,组成两个三角形,使得其互不相交 问有多少种选法 大致思路 考虑枚举一条直线,将所有得点分为左右两部分,其中有两个点在直线上, 以这两个点为顶点,分别统 ...
- Codeforces 15 E. Triangles
http://codeforces.com/problemset/problem/15/E 题意: 从H点走下去,再走回H点,不能走重复路径,且路径不能把黑色三角形包围的方案数 中间的黑色三角形把整张 ...
- Codeforces 793C - Mice problem(几何)
题目链接:http://codeforces.com/problemset/problem/793/C 题目大意:给你一个捕鼠器坐标,和各个老鼠的的坐标以及相应坐标的移动速度,问你是否存在一个时间点可 ...
- 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 ...
- Codeforces - 77B - Falling Anvils - 几何概型
https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...
- 【codeforces 229C】Triangles
[题目链接]:http://codeforces.com/problemset/problem/229/C [题意] 给你一张完全图; 然后1个人从中选择m条边; 然后另外一个人从中选择剩余的n*(n ...
- Codeforces 553C Love Triangles(图论)
Solution: 比较好的图论的题. 要做这一题,首先要分析love关系和hate关系中,love关系具有传递性.更关键的一点,hate关系是不能成奇环的. 看到没有奇环很自然想到二分图的特性. 那 ...
- codeforces 659D . Bicycle Race 几何
题目链接 对相邻的三个点叉积判断一下就好. #include <iostream> #include <vector> #include <cstdio> #inc ...
- [CF1025F]Disjoint Triangles[极角排序+组合计数]
题意 平面上有 \(n\) 个点,选出六个点构成两个三角形,问有多少种构造方式使得两个三角形没有交集. \(n\leq 2000\) 分析 枚举连接两个三角形的两个顶点,同时能够将两个三角形划分在直线 ...
随机推荐
- bootstrap-select 使用笔记 设置选中值及手动刷新
直接笔记: 1.页面刚加载完填充select选项数据时,需要手动刷新一下组件,否则没有选项值.(组件初始化时,li 与 option 分离的,需要刷新一下(据说)) $.post('/cpms/tod ...
- JAVA抠取Excel中的图片
EXCEL中扔了一堆的图片,老大让对应到数据库中的数据上.思路先把图片抠出存成单个图片.然后上传到服务器,取下路径更新到数据库中. 注释掉的部分为有多个Excel时使用. package com.** ...
- [POI2009]Wie
题目 BZOJ 虽然是解压题但也学到了简洁的码风 做法 \(dijkstra\)跑动规 My complete code #include<bits/stdc++.h> #include& ...
- Windows下MarialDB使用
命令行控制启动和关闭:mysqld --console #这样启动ctrl+c即为关闭 启动:双击mysqld.exe即可 #此为后台启动 关闭:mysqladmin -uroot -pr ...
- java常用日期操作方法
package com.wujiangpo.test.util; import java.text.ParseException; import java.text.SimpleDateFormat; ...
- get_called_class--后期静态绑定("Late Static Binding")类的名称
get_called_class--后期静态绑定("Late Static Binding")类的名称 string get_called_class ( void ) 获取静态方 ...
- dfs的返回条件
用到dfs时要注意设置函数的返回条件,否则会导致一直wa!!!!!
- 一览Swift中的常用关键字
要学习Swift这门语言,就必须先了解Swift的关键字及对应的解释.这里就列一下在Swift中常用到的关键字. 关键字是类似于标识符的保留字符序列,除非用重音符号(`)将其括起来,否则不能用作标识符 ...
- relativePath
比如: com.tenace tenace 2.0.1 ../pom.xml //刚开始无此句 com.spider engine 2.6.0-SNAPSHOT tenace作为pom项目已经发布至r ...
- 剑指Offer——重建二叉树2
Question 输入某二叉树的后序遍历和中序遍历的结果,请重建出该二叉树.假设输入的后序遍历和中序遍历的结果中都不含重复的数字.例如输入后序遍历序列{1, 3, 4, 2}和中序遍历序列{1, 2, ...