HDU 6055 17多校 Regular polygon(计算几何)

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

题意:给出n个坐标点(皆在格点上),求问这些点可以构成几个正多边形?

题解:

1.所有点皆在格点上只有一个情况,那便是正四边形

 2.任意枚举两个点,求出另两个点的坐标,来观察是否在给出的点中,若皆存在,cnt++。

求另两个坐标的方法:设已知两个点为a,b(a.x<b.x),另两个点为c,d,设c是直接与b相连的,d是直接与a相连的

如图方法可以求出c-b,d-a的x,y变化分别为 disx=abs(a.y-b.y),disy=abs(a.x-b.x),然后即可以通过一条边计算它左右两个正方形。具体见代码。

3.最后去重,因为一个四边形,它的四条边都计算过它一次,因此将最后的结果/4。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<string.h>
 6 using namespace std;
 7
 8 bool vis[205][205];
 9 //把所有值都加100
10
11 struct node
12 {
13     int x,y;
14 }point[505];
15
16 bool cmp(node a,node b)
17 {
18     return a.x<b.x;
19 }
20
21 bool judge(node c)
22 {
23     if(c.x>=0&&c.x<=200&&c.y>=0&&c.y<=200)
24         if(vis[c.x][c.y])
25             return true;
26     return  false;
27 }
28
29
30 int main()
31 {
32     int n,cnt;
33     while(~scanf("%d",&n))
34     {
35         memset(vis,false,sizeof(vis));
36         for(int i=0;i<n;i++)
37         {
38             scanf("%d%d",&point[i].x,&point[i].y);
39             point[i].x+=100;
40             point[i].y+=100;
41             vis[point[i].x][point[i].y]=true;
42         }
43         sort(point,point+n,cmp);
44         cnt=0;
45         node a,b,c,d;
46         int disx,disy;
47         for(int i=0;i<n;i++)
48         {
49             for(int j=i+1;j<n;j++)
50             {
51                 a=point[i];
52                 b=point[j];
53                 disx=abs(a.y-b.y);
54                 disy=abs(a.x-b.x);
55                 if(b.y<=a.y)
56                 {
57                     //右上
58                     c.x=b.x+disx;
59                     c.y=b.y+disy;
60                     d.x=a.x+disx;
61                     d.y=a.y+disy;
62                     if(judge(c)&&judge(d))
63                         cnt++;
64                     //左下
65                     c.x=b.x-disx;
66                     c.y=b.y-disy;
67                     d.x=a.x-disx;
68                     d.y=a.y-disy;
69                     if(judge(c)&&judge(d))
70                         cnt++;
71                 }
72                 else
73                 {
74                     //右下
75                     c.x=b.x+disx;
76                     c.y=b.y-disy;
77                     d.x=a.x+disx;
78                     d.y=a.y-disy;
79                     if(judge(c)&&judge(d))
80                         cnt++;
81                     //左上
82                     c.x=b.x-disx;
83                     c.y=b.y+disy;
84                     d.x=a.x-disx;
85                     d.y=a.y+disy;
86                     if(judge(c)&&judge(d))
87                         cnt++;
88                 }
89             }
90         }
91         printf("%d\n",cnt/4);
92     }
93     return 0;
94 }
时间: 2024-10-14 09:05:59

HDU 6055 17多校 Regular polygon(计算几何)的相关文章

HDU 6059 17多校3 Kanade&#39;s trio(字典树)

Problem Description Give you an array A[1..n],you need to calculate how many tuples (i,j,k) satisfy that (i<j<k) and ((A[i] xor A[j])<(A[j] xor A[k])) There are T test cases. 1≤T≤20 1≤∑n≤5∗105 0≤A[i]<230 Input There is only one integer T on fi

hdu 4033 Regular Polygon 计算几何 二分+余弦定理

题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #includ

HDU 6045 17多校2 Is Derek lying?

题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 687    Accepted Submission(s): 389 Problem Description Derek and Alfia are good friends.Derek 

HDU 6077 17多校4 Time To Get Up 水题

Problem Description Little Q's clock is alarming! It's time to get up now! However, after reading the time on the clock, Little Q lies down and starts sleeping again. Well, he has 5 alarms, and it's just the first one, he can continue sleeping for a

HDU 6090 17多校5 Rikka with Graph(思维简单题)

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: For an undirected graph G with n nodes and m edges, we can define the distance between 

HDU 6060 17多校3 RXD and dividing(树+dfs)

Problem Description RXD has a tree T, with the size of n. Each edge has a cost.Define f(S) as the the cost of the minimal Steiner Tree of the set S on tree T. he wants to divide 2,3,4,5,6,…n into k parts S1,S2,S3,…Sk,where ?Si={2,3,…,n} and for all d

HDU 6047 17多校 Maximum Sequence(优先队列)

Problem Description Steph is extremely obsessed with "sequence problems" that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one da

HDU 6050 17多校2 Funny Function(数学+乘法逆元)

Problem Description Function Fx,ysatisfies:For given integers N and M,calculate Fm,1 modulo 1e9+7. Input There is one integer T in the first line.The next T lines,each line includes two integers N and M .1<=T<=10000,1<=N,M<2^63. Output For eac

HDU 6092 17多校5 Rikka with Subset(dp+思维)

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has n positive A1−An and their sum is m. Then for each subset S of A, Yuta calcula