题意:要求你分成两个集合,一个是正方形,一个是矩形
思路:n只有8,所以直接暴力就好了
#include<bits\stdc++.h>
using namespace std;
const double eps = 1e-6;
double a[10],b[10];
vector<int>tmp,ans1,ans2;
double dis(int x,int y)
{
return (a[x]-a[y])*(a[x]-a[y])+(b[x]-b[y])*(b[x]-b[y]);
}
double pointx(int x,int y,int z)
{
double x1 = a[y]-a[x],y1 = b[y]-b[x];
double x2 = a[z]-a[x],y2 = b[z]-b[x];
return x1*x2+y1*y2;
}
bool check()
{
double len[4];
for (int i = 0;i<4;i++)
len[i]=dis(tmp[i],tmp[(i+1)%4]);
for (int i = 0;i<4;i++)
for (int j = 0;j<4;j++)
if(fabs(len[i]-len[j])>eps)
return false;
if(fabs(pointx(tmp[0],tmp[1],tmp[3]))>eps)return false;
if(fabs(pointx(tmp[1],tmp[0],tmp[2]))>eps)return false;
if(fabs(pointx(tmp[2],tmp[1],tmp[3]))>eps)return false;
if(fabs(pointx(tmp[3],tmp[2],tmp[0]))>eps)return false;
for(int i=0;i<4;i++)len[i]=dis(tmp[i+4],tmp[(i+1)%4+4]);
if(fabs(len[0]-len[2])>eps)return false;
if(fabs(len[1]-len[3])>eps)return false;
if(fabs(pointx(tmp[4],tmp[5],tmp[7]))>eps)return false;
if(fabs(pointx(tmp[5],tmp[4],tmp[6]))>eps)return false;
if(fabs(pointx(tmp[6],tmp[5],tmp[7]))>eps)return false;
if(fabs(pointx(tmp[7],tmp[6],tmp[4]))>eps)return false;
return true;
}
int main()
{
for(int i=0;i<8;i++)
{
scanf("%lf%lf",&a[i],&b[i]);
tmp.push_back(i);
}
do{
if(check())
{
printf("YES\n");
for(int i=0;i<4;i++)cout<<tmp[i]+1<<" ";
printf("\n");
for(int i=4;i<8;i++)cout<<tmp[i]+1<<" ";
return 0;
}
}while(next_permutation(tmp.begin(),tmp.end()));
printf("NO\n");
}