HDU 6055 Regular polygon(幾何)

Mr_Treeeee發表於2020-04-06

Regular polygon

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


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
 

題意:
給你n個點,問你可以確定幾個不同的正多邊形。

POINT:
一頓瞎猜成功知道了只有正方形的情況。之後反正只有500個點,就遍歷2個點,可以確定2個正方形,看看另外2對頂點存不存在就行了,別忘記/8去重。
因為mp陣列來記錄地圖上有沒有點,並且把負點都加了200來變正,那麼點在判斷的時候其實會超出地圖一倍。
比如(0,300)和(300,300) 你得判斷(300,600)-(0,600)和(0,0)-(300,0)有沒有點,所以陣列要開大,乾脆開一千。還有就是點為負的情況去掉,也會陣列越界。上面的點都處理變正了,不需要考慮負點。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define LL long long
int mp[1000][1000];
int x[555],y[555];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(mp,0,sizeof mp);
        for(int i=1;i<=n;i++)
        {
            scanf("%d %d",&x[i],&y[i]);
            x[i]+=200,y[i]+=200;
            mp[x[i]][y[i]]=1;
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i==j) continue;
                int a=x[i]-x[j];
                int b=y[i]-y[j];
                if(x[i]-b>=0&&y[i]+a>=0&&x[j]-b>=0&&y[j]+a>=0&&mp[x[i]-b][y[i]+a]&&mp[x[j]-b][y[j]+a])
                {
                    ans++;
                }
                if(x[i]+b>=0&&y[i]-a>=0&&x[j]+b>=0&&y[j]-a>=0&&mp[x[i]+b][y[i]-a]&&mp[x[j]+b][y[j]-a])
                    ans++;
            }
        }
        printf("%d\n",ans/8);
    }
}


相關文章