UVA 1595 找對稱軸(set)
阿新 • • 發佈:2019-01-04
題意
給出n個點的橫縱座標,是否可以找出一條豎線,使左右點都對稱。
分析
這個想複雜了。。。
什麼座標離散化了。。
還有一直下意識的關心 點不能用重了。。。
各種標記之類的。。。
其實可以直接 用set遍歷 找這一點,存在不存在關於軸對稱的另一個點。。
程式碼
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main()
{
//freopen("in.txt","r",stdin);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
set<P> s;
int sum = 0;
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
sum += x;
s.insert(P(x*n,y));
}
int f = 0;
for(set <P>::iterator it = s.begin(); it != s.end(); it++)
{
P m = *it;
if(s.find(P(sum*2.0-m.first,m.second)) == s.end())
{
f = 1;
break;
}
}
cout << (f ? "NO" : "YES") << endl;
}
return 0;
}