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
换个思想思考,判断五个点两两之间的距离,保留最小的五个长度,判断这五个长度是否相等!
水题,不多解释,注意保留位数应该在最后计算结果保留!
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
double square(double a)
{
return a*a;
}
int main()
{
int t;
cin>>t;
while(t--)
{
double x[6],y[6];
for(int i=0;i<5;i++)
cin>>x[i]>>y[i];
double dis[11];
int count=0;
for(int i=0; i<4; i++)
{
for(int j=i+1; j<5; j++)
{
dis[count++]=
sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) );
// cout<<i<<endl;
}
}
sort(dis,dis+10);
long long int mark[6];
int num=0;
for(int i=0;i<4;i++)
{
mark[i+1]=dis[i+1]*1000;
mark[i]=dis[i]*1000;
if(mark[i]==mark[i+1])
num++;
}
if(num==4)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}