codeforces 660D D. Number of Parallelograms(计算几何)
题目链接:
4 seconds
256 megabytes
standard input
standard output
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.
Print the only integer c — the number of parallelograms with the vertices at the given points.
4
0 1
1 0
1 1
2 0
1 题意: 给了这么些点,问能形成多少个平行四边形; 思路: 把所有的线段找出来,按长度排序,平行四边形对边长度相等且互相平行,然后判断一下就好了,我的由于每个都算了4遍,所以最后/4;
比赛还没完我就写题解了,说不定还要被hack,好方,哈哈哈哈; AC代码:
/*
2014300227 660D - 4 GNU C++11 Accepted 468 ms 80348 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+;
typedef long long ll;
const double PI=acos(-1.0);
int n,cnt=,vis[*N];
ll x[],y[];
struct Line
{
int fi,se;
ll le;
};
Line line[*N];
int cmp(Line a,Line b)
{
return a.le<b.le;
}
int findpos(ll num)
{
int l=,r=cnt-,mid;
while(l<=r)
{
mid=(l+r)>>;
if(line[mid].le<num)l=mid+;
else r=mid-;
}
return l;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%I64d%I64d",&x[i],&y[i]);
}
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
line[cnt].fi=i;
line[cnt].se=j;
line[cnt++].le=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
} sort(line+,line+cnt,cmp);
vis[]=;
for(int i=;i<cnt;i++)
{
if(line[i].le==line[i-].le)
{
vis[i]=vis[i-];
}
else vis[i]=i;
}
int ans=;
for(int i=;i<cnt;i++)
{
int pos=vis[i];
for(int j=pos;j<cnt;j++)
{
if(line[j].le>line[i].le)break;
if(line[j].fi==line[i].se||line[j].se==line[i].fi||line[j].fi==line[i].fi||line[j].se==line[i].se)continue;
int cx,cy,dx,dy;
cx=line[i].fi;
cy=line[i].se;
dx=line[j].fi;
dy=line[j].se;
if((x[cx]-x[cy])*(y[dx]-y[dy])==(y[cx]-y[cy])*(x[dx]-x[dy]))
ans++;
}
}
cout<<ans/<<"\n"; return ;
}
codeforces 660D D. Number of Parallelograms(计算几何)的更多相关文章
- 【CodeForces 660D】Number of Parallelograms(n个点所能组成的最多平行四边形数量)
You are given n points on a plane. All the points are distinct and no three of them lie on the same ...
- CodeForces - 660D:Number of Parallelograms (问N个点多少个平行四边形)
pro:给定N个点,问多少个点组成了平行四边形.保证没有三点共线. sol:由于没有三点贡献,所以我们枚举对角线,对角线的中点重合的就是平行四边形.如果没说保证三点不共线就不能这么做,因为有可能4个点 ...
- Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- Number of Parallelograms(求平行四边形个数)
Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- D. Number of Parallelograms
D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...
- D. Number of Parallelograms 解析(幾何)
Codeforce 660 D. Number of Parallelograms 解析(幾何) 今天我們來看看CF660D 題目連結 題目 給你一些點,求有多少個平行四邊形. 前言 @copyrig ...
- CodeForces 660D Number of Parallelograms
枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...
随机推荐
- VueJS计算属性: computed
computed属性 HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...
- 【转载】ORM的概念, ORM到底是什么
一.ORM简介 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术.简单的说,ORM是通过使 ...
- 【甘道夫】Ubuntu14 server + Hadoop2.2.0环境下Sqoop1.99.3部署记录
第一步.下载.解压.配置环境变量: 官网下载sqoop1.99.3 http://mirrors.cnnic.cn/apache/sqoop/1.99.3/ 将sqoop解压到目标文件夹,我的是 /h ...
- Ajax请求的跨域(CORS)问题
用浏览器,通过XHR(XMLHttpRequest)请求向另外一个域名请求数据时.会碰到跨域(CORS)问题. CORS:Cross-Origin Resource Sharing 什么是跨域? 简单 ...
- 一份还热乎的蚂蚁面经(已拿Offer)!附答案!!
本文来自我的知识星球的球友投稿,他在最近的校招中拿到了蚂蚁金服的实习生Offer,整体思路和面试题目由作者--泽林提供,部分答案由Hollis整理自知识星球<Hollis和他的朋友们>中「 ...
- js运算【按位非】~
这个运算符有点意思:按位非[~] 先来几个例子: ~undefined: -1 ~false: -1 ~true: -2 ~10:-11 找出规律了吧~~ 再说一下运用场景: 之前判断字符串是否存在是 ...
- 复习Java虚拟机:JVM中的Stack和Heap
在JVM中,内存分为两个部分,Stack(栈)和Heap(堆).这里,我们从JVM的内存管理原理的角度来认识Stack和Heap,并通过这些原理认清Java中静态方法和静态属性的问题. 一般,JVM的 ...
- WPF之DataGrid篇:DataGridComboBoxColumn
准备数据源 1 准备数据源.基类为Student,数据对象为Student3,数据集为StuList3. END 编辑DataGrid显示列 1 若要填充下拉列表,请首先使用下列选项之一设置 ...
- 【BZOJ2843】极地旅行社 离线+树链剖分+树状数组
[BZOJ2843]极地旅行社 Description 不久之前,Mirko建立了一个旅行社,名叫“极地之梦”.这家旅行社在北极附近购买了N座冰岛,并且提供观光服务.当地最受欢迎的当然是帝企鹅了,这些 ...
- Python中属性
属性定义的两种方式: 1.num1=property(GetNum,SetNum) class Pro(): def __init__(self): self._num= def GetNum(s ...