HDU 6055 Regular Polygon (find square) __ Computational geometry

Source: Internet
Author: User
Description

On a two-dimensional plane, give for you n integer points. Your task is to figure out how many different regular polygon this can make.

Input

The input file consists of several test cases. Each case the the "a" is a numbers n (n <= 500). The next N lines, each line contain two number Xi and Yi ( -100 <= xi,yi <=), means the points ' position. (The data assures no two points share the same position.)

Output

For each case, the output a number means how many different regular polygon this points can make.

Sample Input

4
0 0 0 1 1 0 1 1 6 0 0 0 1 1 0 1 1 2 0 2-
1

Sample Output

1
2

the

Given the n points in the plane, ask how many of the four dots are in total.

train of Thought

Because n≤500 n≤500, we can enumerate four points and then we'll go over time.

Looking for a square, you just need to know the two opposite points to calculate the other two points.

So we just need to enumerate two points and then compute the coordinates of the other two points, and if they do, we find the squares, otherwise we don't.

We can use binary or hash methods to determine whether or not a point has occurred.

AC Code

#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <vector&
Gt

#include <iostream> using namespace std;
#define EPS 1e-7 struct node {double x,y;} p[510];

int n;
    BOOL CMP (node A,node b) {if (a.x==b.x) return a.y<b.y;
Return a.x<b.x;
    BOOL Judge (double x,double y)//Two-point lookup {int low=0,high=n-1;
        while (low<=high) {int mid= (Low+high)/2;
        if (Fabs (p[mid].x-x) <eps&&fabs (p[mid].y-y) <eps) return true; else if (p[mid].x-x>eps| |
            (Fabs (p[mid].x-x) <eps&&p[mid].y-y>eps))
        High=mid-1;
    else low=mid+1;
return false;
    int main () {Ios::sync_with_stdio (false);
        while (cin>>n) {int ans=0;
        for (int i=0; i<n; i++) cin>>p[i].x>>p[i].y;
        Sort (p,p+n,cmp); for (int i=0; i<n; i++) {for (int j=i+1; j<n; j++) {if (i==j) continue;
                Double xa= (p[i].x+p[j].x)/2.0;
                Double ya= (P[I].Y+P[J].Y)/2.0;
                Double Xb=p[i].x-xa;
                Double Yb=p[i].y-ya;
            if (judge (XA+YB,YA-XB) &&judge (XA-YB,YA+XB)) ans++;
    }} cout<<ans/2<<endl;
return 0; }

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.