题意:给n个点找正方形
思路:直接DFS
#include<bits/stdc++.h>
using namespace std;
const int maxn = 40;
int n,ans;
int vis[maxn];
struct point
{
int x,y;
}points[maxn];
bool cmp(const point a,const point b)
{
if (a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
}
int check(int x,int y)
{
for (int i = 0;i<n;i++)
if (!vis[i] && points[i].x==x && points[i].y==y)
return i;
return -1;
}
void dfs(int num)
{
if (num > ans)
ans = num;
for (int i = 0;i<n;i++)
{
if (!vis[i])
{
for (int j = i+1;j<n;j++)
{
if ((points[j].x-points[i].x)==(points[j].y-points[i].y) && points[j].x-points[i].x)
{
int t1 = check(points[i].x,points[j].y);
int t2 = check(points[j].x,points[i].y);
if (t1!=-1 && t2!=-1)
{
vis[t1]=1;
vis[t2]=1;
vis[j]=1;
vis[i]=1;
dfs(num+1);
}
}
}
}
}
}
int main()
{
while (scanf("%d",&n)!=EOF && n!=-1)
{
for (int i = 0;i<n;i++)
scanf("%d%d",&points[i].x,&points[i].y);
sort(points,points+n,cmp);
ans = 0;
memset(vis,0,sizeof(vis));
dfs(0);
printf("%d\n",ans*4);
}
}