hdu6055

来源:互联网 发布:2017格里芬体测数据 编辑:程序博客网 时间:2024/05/21 09:12
贵州”创新大赛 !

Regular polygon

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


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
40 00 11 01 160 00 11 01 12 02 1
 

Sample Output
12
思路:这题其实是找正方形有多少个就可以了,已知两个点就可以枚举其他点是否和给出的一样,最后还要除以8。
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <cmath>#include <stdlib.h>#include <vector>#include <queue>#include <stack>using namespace std;const int MOD=1e9+7;vector<int>a1;vector<int>a2;int v[100005];int x[3005],y[3005];int ma[2055][2055];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int i,j;        memset(ma,0,sizeof(ma));        for(i=0;i<n;i++)        {            scanf("%d %d",&x[i],&y[i]);            x[i]+=300;            y[i]+=300;            ma[x[i]][y[i]]=1;        }        long long int sum=0;        for(i=0;i<n;i++)        {            for(j=0;j<n;j++)            {                if(i==j)continue;                int a=x[j]-x[i];                int b=y[j]-y[i];                if(x[i]-b>=0&&y[i]+a>=0&&x[j]-b>=0&&y[j]+a>=0)                    if(ma[x[i]-b][y[i]+a]&&ma[x[j]-b][y[j]+a])                        sum++;                if(x[i]+b>=0&&y[i]-a>=0&&x[j]+b>=0&&y[j]-a>=0)                    if(ma[x[i]+b][y[i]-a]&&ma[x[j]+b][y[j]-a])                        sum++;            }        }        cout<<sum/8<<endl;    }    return 0;}


原创粉丝点击