HDU6055 Regular polygon(计算几何,2017 HDU多校联赛 第2场)

来源:互联网 发布:source tree mac 编辑:程序博客网 时间:2024/06/04 18:32

题目:

Regular polygon

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


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
 

Source
2017 Multi-University Training Contest - Team 2
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6055 6054 6053 6052 6051 
 

Statistic | Submit | Discuss | Note
思路:

题意是给了n个点,问着这个图中有多少个正多边形


因为所给出的坐标是整数,满足整这个条件的正多边形只有正方形,所以我们把每两个点枚举一遍,看看是否存在形成正方形另外两个点,因为把每一个边都枚举了一遍,所以最后的答案要除以4


枚举的时候,知道了两个点,每两个点我们要在它的左右两边找正方形,所以我们要判断两次


代码:

#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define N 250010#define ll long longusing namespace std;int vis[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;//  printf("a.x=%d,a.y=%d,b.x=%d,b.y=%d\n",a.x-200,a.y-200,b.x-200,b.y-200);//  printf("(%d,%d),(%d,%d),x=%d,y=%d\n",a.x+y-200,a.y-x-200,b.x+y-200,b.y-x-200,x,y);//  printf("(%d,%d),(%d,%d),x=%d,y=%d\n",a.x-y-200,a.y+x-200,b.x-y-200,b.y+x-200,x,y);if(a.x+y>=0&&a.y-x>=0&&b.x+y>=0&&b.y-x>=0&&vis[a.x+y][a.y-x]&&vis[b.x+y][b.y-x])ans++;if(a.x-y>=0&&a.y+x>=0&&b.x-y>=0&&b.y+x>=0&&vis[a.x-y][a.y+x]&&vis[b.x-y][b.y+x])ans++;return ans;}int main(){int n,a,b;while(~scanf("%d",&n)){mem(vis,0);for(int i=0; i<n; i++){scanf("%d%d",&a,&b);a+=200;b+=200;p[i].x=a;p[i].y=b;vis[a][b]=1;}int ans=0;for(int i=0; i<n; i++)for(int j=i+1; j<n; j++)if(i!=j)ans+=solve(p[i],p[j]);printf("%d\n",ans/4);}}


原创粉丝点击