hdu 5563 Clarke and five-pointed star 水题

时间:2023-03-09 07:18:24
hdu 5563 Clarke and five-pointed star 水题

Clarke and five-pointed star

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5563

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

题意

给你五个点,问你是否能够构成一个正五边形,精度要求1e-4

题解:

直接判断是否有五条边相同,是否有五条对角线长度相同就好了

代码

#include<iostream>
#include<stdio.h>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
const double eps = 1e-;
struct node
{
double x,y;
};
node p[];
vector<double> Q;
double dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int is_equal(double x,double y)
{
return fabs(x-y)<eps;
}
map<long long,int> H;
int main()
{
int t;scanf("%d",&t);
for(int cas=;cas<=t;cas++)
{
H.clear();
Q.clear();
for(int i=;i<;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
for(int i=;i<;i++)
{
for(int j=i+;j<;j++)
{
Q.push_back(dis(p[i],p[j]));
}
}
int flag = ;
sort(Q.begin(),Q.end());
for(int i=;i<Q.size();i++)
{
long long p = (100000.0*Q[i])*1LL;
if(H[p]==)
{
H[p]++;
flag++;
}
else
H[p]++;
}
if(flag>)
{
printf("No\n");
continue;
}
long long p1 = 1LL*(100000.0*Q[]);
long long p2 = 1LL*(100000.0*Q[]);
if(H[p1]==)
{
printf("Yes\n");
continue;
}
if(H[p1]!=&&H[p2]!=)
{
printf("No\n");
continue;
}
printf("Yes\n");
}
}