HDU6055 Regular polygon(2017多校第二场)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tju_peter/article/details/76229504

Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1087    Accepted Submission(s): 405


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

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

Output
For each case, output a number means how many different regular polygon these 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
 

Source
论文???
被队友先入为主了,刚开始提了一下整数,后来想到死也没想出来,直接暴力了。

#include <iostream>
#include <cstring>

using namespace std;

int n,ans,a,b;

bool mapc[205][205];

struct point
{
    int x,y;
};

int judge(point a,point b)
{
    int x1 = a.x, y1 = a.y, x2 = b.x, y2 = b.y;
    int res = 0;
    int x3 = -y2+y1+x1 ,y3 = x2-x1+y1;
    int x4 = x3-x1+x2 ,y4 = y3-y1+y2;
    int x5 = 2*x1-x3 ,y5 = 2*y1-y3;
    int x6 = 2*x2-x4 ,y6 = 2*y2-y4;
    if( (x3<=100 && x3>=-100) && (y3<=100 && y3>=-100)
       && (x4<=100 && x4>=-100) && (y4<=100 && y4>=-100)
       && mapc[x3+100][y3+100] && mapc[x4+100][y4+100] )
        res++;
    if( (x5<=100 && x5>=-100) && (y5<=100 && y5>=-100)
       && (x6<=100 && x6>=-100) && (y6<=100 && y6>=-100)
       && mapc[x5+100][y5+100] && mapc[x6+100][y6+100] )
        res++;
    return res;
}

point p[505];
int main()
{
    while(cin>>n)
    {
        ans=0;
        memset(mapc,0,sizeof(mapc));
        for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            p[i].x=a,p[i].y=b;
            mapc[a+100][b+100]=1;
        }
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                ans+=judge(p[i],p[j]);
        cout<<ans/4<<endl;
    }

    return 0;
}


猜你喜欢

转载自blog.csdn.net/tju_peter/article/details/76229504
今日推荐