Clarke and five-pointed star
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 590 Accepted Submission(s): 312
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.
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.
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. )
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 NoHint![]()
![]()
题意:给定五个点,判断它们能否组成五角星。
直接暴力枚举即可。
AC代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f
#define eps 1e-4
#define MAXN (100+10)
#define MAXM (100000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
struct Point{
double x, y;
Point(){}
Point(double X, double Y){
x = X; y = Y;
}
};
Point P[5];
double d0[5], d1[5], d2[5], d3[5], d4[5];
int dcmp(double x)
{
if(fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
}
double dis(Point A, Point B){
return (A.x-B.x) * (A.x-B.x) + (A.y-B.y) * (A.y-B.y);
}
int main()
{
int t; Ri(t);
W(t)
{
for(int i = 0; i < 5; i++)
Rf(P[i].x), Rf(P[i].y);
for(int i = 0; i < 5; i++)
d0[i] = dis(P[0], P[i]);
for(int i = 0; i < 5; i++)
d1[i] = dis(P[1], P[i]);
for(int i = 0; i < 5; i++)
d2[i] = dis(P[2], P[i]);
for(int i = 0; i < 5; i++)
d3[i] = dis(P[3], P[i]);
for(int i = 0; i < 5; i++)
d4[i] = dis(P[4], P[i]);
sort(d0, d0+5);
sort(d1, d1+5);
sort(d2, d2+5);
sort(d3, d3+5);
sort(d4, d4+5);
bool flag = true;
for(int i = 0; i < 5; i++)
{
if(dcmp(d0[i]-d1[i]) || dcmp(d0[i]-d2[i]) || dcmp(d0[i]-d3[i]) || dcmp(d0[i]-d4[i]))
{
flag = false;
break;
}
}
printf(flag ? "Yes\n" : "No\n");
}
return 0;
}