Number of Parallelograms
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the only integer c — the number of parallelograms with the vertices at the given points.

Example
input
4 0 1 1 0 1 1 2 0
output
1
题解:平行四边形的中点是确定的,那么根据两两边的中点,如果有重合那么可以组成平行四边形;
代码:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner; public class 平行四边形数 {
static Scanner cin = new Scanner(System.in);
public static void main(String[] argvs){
int N = cin.nextInt();
Point[] a = new Point[N];
for(int i = ; i < N; i++){
a[i] = new Point();
a[i].x = cin.nextDouble();
a[i].y = cin.nextDouble();
//a[i].Put();
}
Point[] b = new Point[N * (N + )/];
int tp = ;
for(int i = ; i < N*(N + )/; i++)
b[i] = new Point();
for(int i = ; i < N; i++){
for(int j = i + ; j < N; j++){
if(a[i].x == a[j].x && a[i].y == a[j].y)
continue;
b[tp++] = Point.getp(a[i], a[j]);
}
} Arrays.sort(b, , tp, new PointComparator());
// System.out.println("tp = " + tp);
int ans = , cnt = ;
for(int i = ; i < tp; i++){
// System.out.println(b[i].x + " " + b[i].y);
if(b[i].x == b[i - ].x && b[i].y == b[i - ].y){
cnt++;
}
else{
ans += cnt * (cnt - ) / ;
cnt = ;
}
}
System.out.println(ans);
}
} class Point{
static Scanner cin = new Scanner(System.in);
public double x, y;
public void Put(){
x = cin.nextInt();
y = cin.nextInt();
// System.out.println("***" + this.x + " " + this.y);
}
static Point getp(Point a, Point b){
Point c = new Point();
c.x = (a.x + b.x) / ;
c.y = (a.y + b.y) / ;
// System.out.println("***" + c.x + " " + c.y);
return c;
}
}
class PointComparator implements Comparator{
public int compare(Object x, Object y){
Point a = (Point)x;
Point b = (Point)y;
if(a.x != b.x){
if(a.x <= b.x)
return -;
else
return ;
}
else{
if(a.y <= b.y)
return -;
else
return ;
}
}
}

Number of Parallelograms(求平行四边形个数)的更多相关文章

  1. 【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 ...

  2. Parallelogram Counting(平行四边形个数,思维转化)

    1058 - Parallelogram Counting    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...

  3. D. Number of Parallelograms

    D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...

  4. POJ 1791 Parallelogram Counting(求平行四边形数量)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  5. Number of Parallelograms CodeForces - 660D (几何)

    Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...

  6. 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]

    [本文链接] http://www.cnblogs.com/hellogiser/p/single-number-of-array-with-other-three-times.html [题目] i ...

  7. js求连个数之间的数字

    整理出自项目中一个需求,求两个数之间的数字. const week = function(arr,arr2){ let a=parseInt(arr); let b=parseInt(arr2); l ...

  8. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  9. codeforces 660D D. Number of Parallelograms(计算几何)

    题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...

随机推荐

  1. 【剑指offer】二叉树深度

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27249675 题目描写叙述: 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点 ...

  2. QtWebkit2.2.0 HTML5.0支持情况

      Canvas: 支持element, 2d context以及文本 解析规则:支持 HTML5 tokenizer/tree building,  SVG in text/html, MathML ...

  3. Linux基础知识(二)

    1. 请回答,32位和64位有什么区别呢?什么时候安装32位的,又什么时候安装64位操作系统呢?如何查看系统是32位的还是64位的? 所谓的32位.64位指的是CPU的GPRs(General-Pur ...

  4. 原生js获取body

    1. doucumnet.body 2. document.getElementsByTagName("body")[0]

  5. MS-SQL数据库备份方法

    一.手动备份 打开企业管理器 --> 右键点击需要备份的数据库 --> 所有任务 --> 备份数据库 或者: 查询分析器: use master  backup database 数 ...

  6. EF数据存贮问题二之“无法定义这两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象”

    “无法定义这两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象”,这是在EF中,一对多关系表,有外键的类保存至数据库中出现的错误. 我原来是用JAVA开发的,习惯性的处理一对多 ...

  7. Android中多表的SQLite数据库(译)

    原文: Android SQLite Database with Multiple Tables 在上一篇教程Android SQLite Database Tutorial中,解释了如何在你的And ...

  8. 数据泵导出/导入Expdp/impdp

    一下转自 http://blog.csdn.net/jionjionyoushen/article/details/6789686 数据泵导出/导入Expdp/impdp Oracle 10g引入了D ...

  9. Convert.ToInt32()和int.Parse()的区别

    (1)Convert.ToInt32(null)会返回0而不会报异常,但int.Parse(null)则会产生异常 (2)Convert.ToInt32("")和int.Parse ...

  10. 优化PHP代码的40条建议(转载)

    [size=5][color=Red](译文)优化PHP代码的40条建议[/color][/size] 40 Tips for optimizing your php Code 原文地址:http:/ ...