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
题解:平行四边形的中点是确定的,那么根据两两边的中点,如果有重合那么可以组成平行四边形;
代码:
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(求平行四边形个数)的更多相关文章
- 【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 ...
- Parallelogram Counting(平行四边形个数,思维转化)
1058 - Parallelogram Counting PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...
- D. Number of Parallelograms
D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...
- POJ 1791 Parallelogram Counting(求平行四边形数量)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...
- 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]
[本文链接] http://www.cnblogs.com/hellogiser/p/single-number-of-array-with-other-three-times.html [题目] i ...
- js求连个数之间的数字
整理出自项目中一个需求,求两个数之间的数字. const week = function(arr,arr2){ let a=parseInt(arr); let b=parseInt(arr2); l ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- codeforces 660D D. Number of Parallelograms(计算几何)
题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...
随机推荐
- spark 高级算子
mapPartitionsWithIndex val func = (index: Int, iter: Iterator[(Int)]) => { iter.toList.map(x ...
- 页面显示磁盘空间使用情况-Agedu
下载:http://www.chiark.greenend.org.uk/~sgtatham/agedu/ [root@localhost ~]# tar zxvf agedu-r9723.tar.g ...
- Hacker(18)----了解Windows系统漏洞
一.WinXP中的漏洞 在WinXP中,常见的漏洞主要有UPNP服务漏洞.帮助与支持中心漏洞.压缩文件夹漏洞.服务拒绝漏洞.RDP漏洞以及热键漏洞. 1.UPNP服务漏洞 漏洞描述:UPNP(Univ ...
- 未能加载文件或程序集“System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”
最近用vs2012发布程序,然后将更新后的程序文件部署到服务器上,由于服务器上本来有此系统,所以只更新了修改的文件 . 进行系统登录时提示:未能加载文件或程序集“System.Web.Extensio ...
- 无法连接到ASP.NET Development Server 解决办法
右击项目名称 -> 属性 -> Web -> 选特定端口 -> 输入一个端口值.
- js获取浏览器滚动条距离顶端的距离
最近在做项目的时候遇到需要用js获取滚动条距离窗口顶端的距离和js获取浏览器可视化窗口的大小,在这儿做一个整理保存: 一.jQuery获取的相关方法 jquery 获取滚动条高度 获取浏览器显示 ...
- http 压缩
HTTP压缩是在Web服务器 和浏览器间传输压缩文本内容的方法.HTTP压缩采用通用的压缩算法如gzip等压缩HTML.JavaScript或 CSS文件.压缩的最大好处就是降低了网络传输的数据量,从 ...
- Js 时间间隔计算(间隔天数)
function GetDateDiff(startDate,endDate) { var startTime = new Date(Date.parse(startDate.replac ...
- Fun with dynamicobject dynamic and the settings table
What came before In my previous post I discussed ways of making the settings table using Generics to ...
- php 序列化储存和转化 json_encode() json_decode($q,true)
序列化是将变量转换为可保存或传输的字符串的过程:反序列化就是在适当的时候把这个字符串再转化成原来的变量使用.这两个过程结合起来,可以轻松地存储和传输数据,使程序更具维护性. 例如:当需要数据库只有一个 ...