题目
判断一个平面上的点是不是关于某条竖线对称。
分析
计算几何。首先利用所有点的横坐标的和计算出折线对应的x,然后将左右分成两组,将x坐标转化成相对折线的距离,排序比较输出。
说明
好多书和论文要看,还要学英语。。。ε=(´ο`*)))唉
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
typedef struct _point
{
double x, y;
}point;
point P[1001];
point L[1001];
point R[1001];
bool cmp(point a, point b)
{
if (a.x == b.x) {
return a.y < b.y;
} else {
return a.x < b.x;
}
}
int main()
{
int T, N;
while (~scanf("%d", &T))
while (T --) {
scanf("%d", &N);
double sum = 0.0;
for (int i = 0; i < N; ++ i) {
scanf("%lf%lf", &P[i].x, &P[i].y);
sum += P[i].x;
}
double mid = sum / N;
int lcount = 0, rcount = 0;
for (int i = 0; i < N; ++ i) {
if (P[i].x < mid) {
L[lcount].x = mid - P[i].x;
L[lcount].y = P[i].y;
lcount ++;
}
if (P[i].x > mid) {
R[rcount].x = P[i].x - mid;
R[rcount].y = P[i].y;
rcount ++;
}
}
int flag = 0;
if (lcount == rcount) {
sort(L, L + lcount, cmp);
sort(R, R + rcount, cmp);
flag = 1;
for (int i = 0; i < lcount; ++ i) {
if (L[i].x != R[i].x || L[i].y != R[i].y) {
flag = 0;
break;
}
}
}
if (flag) {
puts("YES");
} else {
puts("NO");
}
}
return 0;
}