1. 程式人生 > >Uva 1595 暴力列舉

Uva 1595 暴力列舉

#include <iostream>
#include <set>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
struct Node{
    int x,y;
}c[1005];
int temp;
bool comp(struct Node a,struct Node b){
    if(a.x!=b.x)
        return a.x<b.x;
    else{
        if(a.x*2>temp)
            return a.y<b.y;
        else
            return a.y>b.y;
    }
}

bool solve(int k){
    if(k%2==0){
        int mid=c[k/2].x*2;
        for(int i=0;i<k/2;i++){
            if((c[i].x+c[k-i].x)!=mid)
                return 0;
            else{
                if(c[i].x!=c[k-i].x&&c[i].y!=c[k-i].y)
                    return 0;
            }
        }
        return 1;
    }else{
        int mid=c[k/2].x+c[k/2+1].x;
        for(int i=0;i<=k/2;i++)
            if((c[i].x+c[k-i].x)!=mid)
                return 0;
            else{
                if(c[i].x!=c[k-i].x&&c[i].y!=c[k-i].y)
                    return 0;
            }
        return 1;
    }
}
int main()
{
    int t,n;
    while(cin>>t){
        while(t--){
            int minn=999999;
            int maxn=-999999;
            memset(c,0,sizeof(c));
            cin>>n;
            int k=-1;
            while(n--){
                k++;
                cin>>c[k].x>>c[k].y;
                minn=min(c[k].x,minn);
                maxn=max(c[k].x,maxn);
            }
            temp=minn+maxn;
            sort(c,c+k+1,comp);
            bool ans=solve(k);
            if(ans) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
}