FZU-2231 Parallelogram number from the 13th session of Fuzhou University program design Competition

Source: Internet
Author: User

Fzu-problem 2231 Parallelogram number

accept:66 submit:210 time limit:2000 mSec Memory limit:32768 KB

Problem Description

Given n points within a plane, any three points are not on the same line, how many parallelogram can be formed with these points? A point can belong to more than one parallelogram at a time.

Input

Multiple sets of data (<=10), processed to EOF.

The first row of each group of data is an integer n (4<=n<=500). The next n rows are two integers per line xi,yi (0<=XI,YI<=1E9), representing the coordinates of each point.

Output

Each set of data outputs an integer that indicates how many parallelogram can be formed with these points.

Sample Input

4
0 1
1 0
1 1
2 0
Sample Output

1
Source

13th session of Fuzhou University program design Competition

Test instructions
Parallelogram judgment:
1, the two groups of sides are parallel to the four-sided shape is parallelogram (definition determination method);
2, a set of parallel and equal to the side of the four-sided shape is parallelogram;
3, the two groups on the side of the same four-sided shape is parallelogram;
4, two sets of diagonal respectively equal four-sided shape is parallelogram (two pairs of sides parallel judgment);
5, diagonal cross-divided four-sided shape is parallelogram.
If 1-4th, the 500^4 four for traversal ~ absolutely forced super
So ruled out, according to the 5th point, the precondition because three points is not in the same line, so we just have to judge the point of the good,
Central point->x (y) = (point->x1 (y1) + point->x2 (y2))/2
Then we sort the set of central points the same as K for the midpoint, and then, what we do is to calculate k pairs of point sets with a common midpoint (each point set contains two points) how many parallelogram, that is, the number of combinations of CK (bottom) 2 (upper), the expanded type is k* (k-1)/2

#include "iostream"#include "algorithm"Using namespaceSTD;struct node{intx,y;}p[510],CP[250010];int CMP (node A,node b) {if (a. x!=b. x) {return a. x<b. x;}else{return a. Y<b. Y;}}int Main () {int J,i,n,co,k,count;while (Cin>>n) {for (i=1; i<=n; i++) {Cin>>p[i]. x>>p[i]. Y;} CO =0;for (i=1; i<=n-1; i++) {for (j=i+1; j<=n; J + +) {                CP[CO]. x= P[i]. x+ P[j]. x;                CP[co++]. Y= P[i]. Y+ P[j]. Y;}}//From0-co-1SortCP,CP+CO,CMP);K =1;Count =0;for (i=1; i<co; i++) {IfCPI. x==CP[I1]. x&&CPI. Y==CP[I1]. Y) {k++//k a line with the same midpoint} else{//combination Ck2Count + = (k* (k-1)/2);K =1; }} Cout<<count<<endl;} return0;}

FZU-2231 Parallelogram number from the 13th session of Fuzhou University program design Competition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.