hdu--6055--Regular polygon

心已赠人 2022-06-11 02:25 283阅读 0赞

Regular polygon

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

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

  1. 4
  2. 0 0
  3. 0 1
  4. 1 0
  5. 1 1
  6. 6
  7. 0 0
  8. 0 1
  9. 1 0
  10. 1 1
  11. 2 0
  12. 2 1

Sample Output

  1. 1
  2. 2

Source

2017 Multi-University Training Contest - Team 2

官方题解:

题意,二维平面上给N个整数点,问能构成多少个不同的正多边形。 题解:容易得知只有正四边形可以使得所有的顶点为整数点。(具体证明可参考杨景钦在2017的国家队论文) 所以正解即求出所有的正四边形个数。 枚举2个点,然后暴力判断另外2个点的位置是否存在。 复杂度 N*N*logN。

我的思路:

因为组成的形状只有正方形,可以先找到正方形的一个边,根据组成这条边的两个端点,推出可以和他们可以组成正方形的点(这条线的两边都要考虑),如果这两个点在给出的点中,ans就加加; 因为数据量很小,直接枚举就好啦 枚举两个点,算出他们的向量,然后去查找是否存在组成正方形的点, 结果除8 代码:

C++ Code











1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48





#include<stdio.h>


#include<algorithm>


#include<string.h>


int aim[
500][
500];


struct Point

{

    
int x,y;

}p[
555];


int solve(Point a,Point b)

{

    
int x=a.x-b.x;

    
int y=a.y-b.y;

    
int ans=
0;

    
///查找这条边的一侧
    
if(a.x+y>=
0&&a.y-x>=
0&&b.x+y>=
0&&b.y-x>=
0&&aim[a.x+y][a.y-x]&&aim[b.x+y][b.y-x])

    ans++;

    
///查找这条边的另一侧
    
if(a.x-y>=
0&&a.y+x>=
0&&b.x-y>=
0&&b.y+x>=
0&&aim[a.x-y][a.y+x]&&aim[b.x-y][b.y+x])

    ans++;

    
return ans;

}


int main()

{

    
int n;

    
while(scanf(
“%d”,&n)==
1)

    {

        memset(aim,
0,
sizeof(aim));

        
for(
int i=
0;i<n;i++)

        {

            
int a,b;

            scanf(
“%d%d”,&a,&b);

            a+=
100;b+=
100;

            p[i].x=a;

            p[i].y=b;

            aim[a][b]=
1;

        }

        
int ans=
0;

        
for(
int i=
0;i<n;i++)

        {

            
for(
int j=
0;j<n;j++)

            
if(i!=j)

                ans+=solve(p[i],p[j]);



        }

        printf(
“%d\n”,ans/
8);

    }

}


发表评论

表情:
评论列表 (有 0 条评论,283人围观)

还没有评论,来说两句吧...

相关阅读