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. 软件project(五)——可行性研究

    一.目的 用最小的代价高效率的确定问题是否可以解决. 不是去解决这个问题,而是确定问题是否值得去解决.进行可行性研究简化了系统分析和系统设计的过程. 二.任务 (1)进一步分析问题定义. (2)分析员 ...

  2. unity3d 学习笔记(一)

    操作:按下shit 点击坐标轴中心 切换透视图 动画烘焙的概念:相当于把原来的控制器动画或者IK(骨骼)动画所有塌陷为逐帧动画,导出的时候必须选这一项 着色器:从技术的角度来看,着色器是渲染器的一个部 ...

  3. leetcode:Minimum Path Sum(路线上元素和的最小值)【面试算法题】

    题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...

  4. Javascript高级程序设计读书笔记(第三章)

    第3章 基本概念 3.4 数据类型 5种简单数据类型:undefined.boolean.number.null.string. typeof操作符,能返回下列某个字符串:“undefined”.“b ...

  5. C#之获取本地IP地址

    最近协助一个项目解决了一个获取IP地址的问题,手机客户端与WebService进行通讯,然后WebService通过TCP通讯把指令传递到另一台PC机上.在测试的过程中,总是会出现WebService ...

  6. poj2456 二分逼近寻找正确答案

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10078   Accepted: 4988 ...

  7. T-SQL语句——UNION, EXCEPT, INTERSECT

    UNION,EXCEPT, INTERSECT关键字用于对集合的查询,它们的作用分别为: UNION:合并两个或多个 SELECT 语句的结果集,并把重复结果去除: UNIONALL:合并两个或多个 ...

  8. iOS开发笔记--什么时候调用layoutSubviews

    iOS开发笔记--什么时候调用layoutSubviews 分类: iOS2014-04-22 16:15 610人阅读 评论(0) 收藏 举报 今天在写程序时候遇见layoutSubviews触发时 ...

  9. ios 多线程 面试

    1 多线程是什么  同步完成多项任务,提高了资源的使用效率,从硬件.操作系统.应用软件不同的角度去看,多线程被赋予不同的内涵,对于硬件,现在市面上多数的CPU都是多核的,多核的CPU运算多线程更为出色 ...

  10. linux里忘记root密码解决办法

    1:打开虚拟机,点‘启动’按钮, 2:出现上面这个界面时,键盘输入’i’,出现grub界面: 3:键盘输入e,出现如下界面: 4:选择第二行(kernel……) 5:键盘输入e,出现如下界面: 6:在 ...