【题目链接】 http://acm.hdu.edu.cn/showproblem.php?pid=6055
题目意思
给定n个点问你可以形成多少个正多边形。
解题思路
因为给定点为整数,所以只能形成正4边形,因此从上往下,从左往右。任意两个点两两判断剩余其余两点是否在给定点中,最后答案除2,因为ab和ba重复计算
代码部分
#include <bits/stdc++.h>
using namespace std;
const int maxn=
510;
struct Node
{
int x,y;
bool operator<(
const Node &rhs)
const
{
if(x == rhs.x)
return y < rhs.y;
else
return x < rhs.x;
}
} nodes[maxn];
int main()
{
int n;
while(~
scanf(
"%d",&n))
{
int ans=
0;
for(
int i=
0; i<n; ++i)
scanf(
"%d%d",&nodes[i].x,&nodes[i].y);
sort(nodes,nodes+n);
for(
int i=
0; i<n; ++i)
for(
int j=i+
1; j<n; ++j)
{
Node tmp;
tmp.x=nodes[i].x+nodes[i].y-nodes[j].y;
tmp.y=nodes[i].y+nodes[j].x-nodes[i].x;
if(!binary_search(nodes,nodes+n,tmp))
continue;
tmp.x=nodes[j].x+nodes[i].y-nodes[j].y;
tmp.y=nodes[j].y+nodes[j].x-nodes[i].x;
if(!binary_search(nodes,nodes+n,tmp))
continue;
++ans;
}
printf(
"%d\n",ans/
2);
}
return 0;
}