UVa 1595 Symmetry [Ad Hoc]

本文介绍了一种算法,用于判断一组点是否关于X轴存在对称轴。通过使用C++ set数据结构存储点对,算法计算点集的最大和最小X坐标,以确定潜在的对称轴位置,并检查每一点是否有其对称点。

#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();
  }
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值