您的位置:首页 > 其它

HDU 5562 Clarke and five-pointed star (BC)

2016-07-15 20:14 591 查看


Clarke and five-pointed star


Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)


Total Submission(s) : 8   Accepted Submission(s) : 2


Font: Times New Roman | Verdana | Georgia


Font Size: ← →


Problem Description

Clarke is a patient with multiple personality disorder. One day, Clarke turned into a learner of geometric. 

When he did a research with polygons, he found he has to judge if the polygon is a five-pointed star at many times. There are 5 points on a plane, he wants to know if a five-pointed star existed with 5 points given.


Input

The first line contains an integer T(1≤T≤10),
the number of the test cases. 

For each test case, 5 lines follow. Each line contains 2 real numbers xi,yi(−109≤xi,yi≤109),
denoting the coordinate of this point.


Output

Two numbers are equal if and only if the difference between them is less than 10−4. 

For each test case, print Yes if
they can compose a five-pointed star. Otherwise, print No.
(If 5 points are the same, print Yes.
)


Sample Input

2
3.0000000 0.0000000
0.9270509 2.8531695
0.9270509 -2.8531695
-2.4270509 1.7633557
-2.4270509 -1.7633557
3.0000000 1.0000000
0.9270509 2.8531695
0.9270509 -2.8531695
-2.4270509 1.7633557
-2.4270509 -1.7633557



Sample Output

Yes
No



Hint






Source

BestCoder Round #62 (div.2)

分析:给出5个点的坐标,判断是否是一个正五角星

方法一:判断是正五角星,只需要判断是正五边形,因为输入的点是随机输入的,所以先把点按逆时针排一下序,然后再计算五边形的边是否相等即可。

方法二:把每个点到其他各点的距离求出来,排序,小的五条边是五边形的边,大的五条边是五边形的对角线。判断小的边相等,大的边相等即可。

代码如下(排序):

#include <stdio.h>
#include <math.h>
typedef struct node{
double x,y;
double k;
}Node;
Node ans[10],left[10],right[10];
double sumx,sumy;
void sort()
{//点的排序
int i,j;
sumx=sumx/5.0;
sumy=sumy/5.0;
int le,ri;
le=ri=0;
for(i=0;i<5;i++)
{
ans[i].k=(ans[i].y-sumy)/(ans[i].x-sumx);
if(ans[i].x<=sumx)
left[le++]=ans[i];
else
right[ri++]=ans[i];
}
for(i=0;i<le-1;i++)
{
for(j=i+1;j<le;j++)
{
if(left[i].k > left[j].k)
{
Node temp=left[i];
left[i]=left[j];
left[j]=temp;
}
}
}
for(i=0;i<ri-1;i++)
{
for(j=i+1;j<ri;j++)
{
if(right[i].k>right[j].k)
{
Node temp=right[i];
right[i]=right[j];
right[j]=temp;
}
}
}
int num=0;
for(i=0;i<le;i++)
ans[num++]=left[i];
for(i=0;i<ri;i++)
ans[num++]=right[i];
}

int main()
{
int T;
int i;
scanf("%d",&T);
while(T--)
{
sumx=sumy=.0;
for(i=0;i<5;i++)
{
scanf("%lf %lf",&ans[i].x,&ans[i].y);
sumx+=ans[i].x;
sumy+=ans[i].y;
}
sort();
double avg = sqrt((ans[0].x-ans[1].x)*(ans[0].x-ans[1].x)+(ans[0].y-ans[1].y)*(ans[0].y-ans[1].y));
int peace=0;
for(i=1;i<4;i++)
{
double temp=sqrt((ans[i].x-ans[i+1].x)*(ans[i].x-ans[i+1].x)+(ans[i].y-ans[i+1].y)*(ans[i].y-ans[i+1].y));
if(fabs(avg - temp)<=0.0001)
continue;
else{
peace=1;
break;
}
}
if(!peace)
printf("Yes\n");
else
printf("No\n");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: