UVa 1595

题意

平面上一些点, 找是否存在一条竖线 是这些点的对称轴

思路

水题
一开始还以为是对称轴 不好做, 后来一读题这对称轴一定是与x轴垂直的竖线, 就很好处理了
用set< pair< int,int> > s; 存下所有点
横坐标最大值和最小值除以二就是对称轴竖线所在的线
然后再对对称轴左边的点逐一判断有没有对称轴右边的对应点即可

AC代码

#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

typedef pair<double,double> PR;
set<PR> s;

int main()
{
    int T, n;
    double x, y;
    double xmax, xmin;
    cin >> T;
    while(T--){
        bool flag = true;
        cin >> n;
        scanf("%lf%lf",&x,&y);
        xmax = x, xmin = x;
        s.insert(make_pair(x,y));
        for( int i = 1; i < n; i++ ){
            scanf("%lf%lf",&x,&y);
            s.insert(make_pair(x,y));
            xmax = x > xmax ? x : xmax;
            xmin = x < xmin ? x : xmin;
        }
        double xx = (xmax + xmin)/2.0;
        set<PR>::iterator it = s.begin();
        for( ; it != s.end(); it++ ){
            if( it->first < xx ){
                if( !s.count(make_pair(2*xx-it->first, it->second)) )
                {
                    flag = false;
                    break;
                }
            }
        }
        if( flag )  cout << "YES" << endl;
        else    cout << "NO" << endl;
        if( !s.empty() )    s.clear();
    }
    return 0;
}
原文地址:https://www.cnblogs.com/JinxiSui/p/9740623.html