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. Android: 在WebView中获取网页源码

    1. 使能javascript: ? 1 webView.getSettings().setJavaScriptEnabled(true); 2. 编写本地接口 ? 1 2 3 4 5 final c ...

  2. HDU 2689 sort it - from lanshui_Yang

    Problem Description You want to processe a sequence of n distinct integers by swapping two adjacent ...

  3. LDAP协议介绍

    LDAP协议基础概念  1. 从用途上阐述LDAP,它是一个存储静态相关信息的服务,适合"一次记录多次读取".经常使用LDAP服务存储的信息: 公司的物理设备信息(如打印机,它的I ...

  4. 线程 (detach的作用)

      线程状态在一个线程的生存期内,可以在多种状态之间转换.不同操作系统可以实现不同的线程模型,定义许多不同的线程状态,每个状 态还可以包含多个子状态.但大体说来,如下几种状态是通用的:       就 ...

  5. transition过渡的趣玩

    本例中将三张图(来自网络)进行堆叠,鼠标悬停触发.附有源代码

  6. 传感器仿真平台——UI绘制模块(二)

    这一章讲的是UI绘制模块 该模块的作用是将实验对象绘制出来,它可能是目标.传感器等等,由于事先并不知道会有哪些物体,也无法事先定义好某个对象该怎么画,以我懒人的性格,得了,就抛给用的人吧~喝前摇一摇, ...

  7. javascript 生成UUID

    代码一: /*! Math.uuid.js (v1.4) http://www.broofa.com mailto:robert@broofa.com Copyright (c) 2010 Rober ...

  8. Tomcat unable to start

    在学习springMvc时,导入springfreemarker 的jar包,写好web.xml,config.xml 后. 部署到tomcat,异常如下: 八月 27, 2016 5:44:41 下 ...

  9. python进行base64编解码

    [转] 直接上代码 import base64 fin = open(r"D:\2.zip", "rb") fout = open(r"D:\2.x. ...

  10. (原)torch7中添加新的层

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6069627.html 参考网址: http://torch.ch/docs/developer-doc ...