传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6055
Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2777 Accepted Submission(s): 1110
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
Recommend
liuyiding
题意:在二维平面内有N个点,判断这n个点能组成多少个正多边形
思路:开始也很懵,不过后来知道坐标是整数点的正多边形只有正方形之后,思路清晰了很多。
贴上一份当时队友的代码:
#include<iostream>
#include<sstream>
#include<fstream>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
#define si(x) scanf("%d", &x)
#define sii(x,y) scanf("%d %d", &x, &y)
#define sl(x) scanf("%ld", &x)
#define sll(x,y) scanf("%ld %ld", &x, &y)
#define fe1(i, a, b) for(int i = a; i <= b; i++)
#define fu(i, a, b) for(int i = a; i < b; i++)
#define MP(x, y) make_pair(x, y)
typedef pair<int , int> pii;
typedef long long LL;
typedef unsigned long long LLu;
const int maxn = 33;
const int inf = 0x3f3f3f3f;
using namespace std ;
#define eqs 1e-9
struct node{
double x , y ;
}p[1100] ;
bool cmp(node a,node b)
{
return ( a.x < b.x || ( a.x == b.x && a.y < b.y ) ) ;
}
bool judge(double x,double y,int n)
{
int low = 0 , mid , high = n-1 ;
while( low <= high )
{
mid = (low + high) / 2 ;
if( fabs(p[mid].x-x) < eqs && fabs(p[mid].y-y) < eqs )
return true ;
else if( p[mid].x-x > eqs || ( fabs(p[mid].x-x) < eqs && p[mid].y-y > eqs ) )
high = mid - 1 ;
else
low = mid + 1 ;
}
return false ;
}
int main()
{
int n , i , j , num ;
double x , y , xx , yy ;
while(~scanf("%d", &n))
{
num = 0 ;
for(i = 0 ; i < n ; i++)
{
scanf("%lf %lf", &p[i].x, &p[i].y) ;
}
sort(p,p+n,cmp) ;
for(i = 0 ; i < n ; i++)
{
for(j = i+1 ; j < n ; j++)
{
if( i == j ) continue ;
x = (p[i].x+p[j].x)/2 ;
y = (p[i].y+p[j].y)/2 ;
xx = p[i].x - x ;
yy = p[i].y - y ;
if( judge(x+yy,y-xx,n) && judge(x-yy,y+xx,n) )
{
num++ ;
}
}
}
printf("%d\n", num/2) ;
}
return 0;
}