UVA1595_Symmetry

给出平面上n个点,问你能不能找到一个竖线让他们对称

这道题后面发现真的不难,又不止一种方法

我当时写的很挫,死脑筋的就找一个点的对称点存不存在,用结构体存点信息,在排序用find找,,然后不知道一堆wa

后面发现排序之后,如果位置i和n-i-1这两个点不对称就一定不存在!!!!

可以用反证法得知

//
//    Created by Zeroxf on 2015-08-19-15.36
//    Copyright: (c) 2015 Zeroxf. All rights reserved
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
struct node{
    int x,y;
    node(int x,int y):x(x),y(y){}
    bool operator < (const node& rhs)const{
        return x < rhs.x||(x==rhs.x&&y<rhs.y);
    }
    bool operator != (const node& rhs)const{
        return x != rhs.x || y != rhs.y;
    }
};
vector<node> v;
const int maxn = 1e5;
long long t,n,sum,ok,mid;
int x,y;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        sum = 0; ok =true;v.clear();
        for(int i = 0; i < n; i++){
            scanf("%d%d",&x,&y);
            sum += x;
            v.push_back(node(x,y));
        }
        if((sum*2)%n != 0) ok = false;
        else {
            sort(v.begin(),v.end());
            mid = sum *2 /n;
            for(int i = 0;i < v.size(); i++){
                node findv(mid-v[i].x,v[i].y);
                int pos = lower_bound(v.begin(), v.end(), findv) - v.begin();
                if(pos>=v.size()||v[pos]!=findv){
                    ok = false;break;
                }
            }
        }
        if(ok) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值