#Description
给你N个点的坐标(X,Y)
判断这这些点是否存在一个垂直于X轴的对称轴
#Algorithm
目前只知道用set做
set可以存对(pair)
不可以存结构体(struct)
然后就是把每个点对存到set里,然后找有没有对称的就可以了
对称轴使用最大X坐标和最小X坐标加起来搞得
#Code
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <set>
using namespace std;
const int MAXL = 20000 + 9;
const int INF = INT_MAX;
typedef pair<int, int> V;
void solve()
{
set<V> myset;
int n;
scanf("%d", &n);
int minx = INF;
int maxx = -INF;
while (n--) {
int x, y;
scanf("%d%d", &x, &y);
minx = min(minx, x);
maxx = max(maxx, x);
myset.insert(V(x, y));
}
int mid2 = maxx + minx;
bool flag = true;
for (set<V>::iterator it = myset.begin(); it != myset.end(); it++) {
if (!myset.count(V(mid2- (*it).first, (*it).second))) {
flag = false;
break;
}
}
if (flag) {
puts("YES");
} else
{
puts("NO");
}
}
int main()
{
//freopen("in.txt", "r", stdin);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
}
本文介绍了一种算法,用于判断一组点是否关于X轴存在对称轴。通过使用C++ set数据结构存储点对,算法计算点集的最大和最小X坐标,以确定潜在的对称轴位置,并检查每一点是否有其对称点。
325

被折叠的 条评论
为什么被折叠?



