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. Unity 对象池的使用

    在游戏开发过程中,我们经常会遇到游戏发布后,测试时玩着玩着明显的感觉到有卡顿现象.出现这种现象的有两个原因:一是游戏优化的不够好或者游戏逻辑本身设计的就有问题,二是手机硬件不行.好吧,对于作为程序员的 ...

  2. 普通用户之间的ssh无密码访问设置方法

    两台CentOS6.2服务器,客户端是node1,服务器是node2,先都用root用户配置,方法如下: 第一步:在客户端Node1:生成密匙对,我用的是rsa的密钥.使用命令 "ssh-k ...

  3. hadoop 2.6.0上安装sqoop-1.99.6-bin-hadoop200

    第一步:下载sqoop-1.99.6-bin-hadoop200.tar.gz  地址:http://www.eu.apache.org/dist/sqoop/1.99.6/ 第二步:将下载好的sqo ...

  4. Tomcat 7.0 进入项目管理页面时的密码问题

    tomcat7 这个版本,官方网下载的原始包项目管理页面的权限和之前版本的配置有点区别. 到Tomcat的conf文件夹下找到tomcat-users.xml文件,有配置权限的配置文件.     ma ...

  5. Oracle函数function

    --function /* 函数是有返回值.-只能有一个返回值. 语法 Create or replace func1(参数) Return varchar2 As Pl/sql块 Return 'J ...

  6. iOS 无限轮播图的两种实现

    首先说一下实现的思想: 用UIScrollView实现,在scrollView上添加3个UIImageView,分别用来显示上一张图片,当前显示的图片,下一张图片.scrollView在不滑动的时候永 ...

  7. PHP 日期格式化 参数参考

    a - "am" 或是 "pm" A - "AM" 或是 "PM" d - 几日,二位数字,若不足二位则前面补零; 如: ...

  8. C/C++中define的使用

    代码: #include <iostream> using namespace std; #define a 10 void foo(); void bar(); void foo(){ ...

  9. Python代码一定要对齐

    不然会出现错误: IndentationError: unindent does not match any outer indentation level PS:新的Python语法,是不支持的代码 ...

  10. HDU 4507 有点复杂却不难的数位DP

    首先来说,,这题我wrong了好几次,代码力太弱啊..很多细节没考虑.. 题意:给定两个数 L R,1 <= L <= R <= 10^18 :求L 到 R 间 与 7 无关的数的平 ...