http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D
改了N多次之后终于A了,一直在改判断正方形和矩形那,判断正方形时算出六条边再排序,若前四条边相等并且与后两条边满足勾股定理,说明是正方形,
判断矩形时,我先对结构体二级排序,这样四个点有确定的顺序,再用点积判断是否有三个角是直角,是的话就是矩形。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; struct node
{
int x,y;
}point[]; int cmp(const struct node a,const struct node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
int dot(const struct node a, const struct node b,const struct node c, const struct node d)
{
int ans = (a.x-b.x)*(c.x-d.x) + (a.y-b.y)*(c.y-d.y);
if(ans == ) return ;
return ;
} int dis(const struct node a, const struct node b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int main()
{
while(~scanf("%d %d",&point[].x,&point[].y))
{
bool vis[] = {false};
for(int i = ; i <= ; i++)
scanf("%d %d",&point[i].x,&point[i].y);
int flag = ;
int cnt;
struct node t_point[];
for(int i = ; i <= ; i++)
{
for(int j = i+; j <= ; j++)
{
for(int k = j+; k <= ; k++)
{
for(int l = k+; l <= ; l++)
{
int distance[];
distance[] = dis(point[i],point[j]);
distance[] = dis(point[i],point[k]);
distance[] = dis(point[i],point[l]);
distance[] = dis(point[j],point[k]);
distance[] = dis(point[j],point[l]);
distance[] = dis(point[k],point[l]);
sort(distance,distance+);
if( distance[] == distance[] &&
distance[] == distance[] &&
distance[] == distance[] &&
distance[] == distance[] &&
(distance[] + distance[] == distance[]))
{
flag = ;
vis[i] = true;
vis[j] = true;
vis[k] = true;
vis[l] = true;
break;
}
}
if(flag) break;
}
if(flag) break;
}
if(flag) break;
}
if(!flag)
printf("NO\n"); else
{
int tmp1[],tmp2[],t1 = ,t2 = ;
cnt = ;
for(int i = ; i <= ; i++)
{
if(!vis[i])
{
t_point[cnt++] = point[i];
tmp2[t2++] = i;
}
else tmp1[t1++] = i;
}
sort(t_point,t_point+cnt,cmp); if(dot(t_point[],t_point[],t_point[],t_point[]) &&
dot(t_point[],t_point[],t_point[],t_point[]) &&
dot(t_point[],t_point[],t_point[],t_point[]))
{
printf("YES\n");
for(int i = ; i < t1-; i++)
printf("%d ",tmp1[i]);
printf("%d\n",tmp1[t1-]);
for(int i = ; i < t2-; i++)
printf("%d ",tmp2[i]);
printf("%d\n",tmp2[t2-]);
}
else printf("NO\n"); } }
return ;
}