24h購物| | PChome| 登入
2012-05-08 16:58:27| 人氣1,005| 回應0 | 上一篇 | 下一篇

[UVA] 10585 - Center of symmetry

推薦 0 收藏 0 轉貼0 訂閱站台

Problem E: Center of symmetry

Given is a set of n points with integer coordinates. Your task is to decide whether the set has a center of symmetry.

A set of points S has the center of symmetry if there exists a point s (not necessarily in S) such that for every point p in S there exists a point q in S such that p-s = s-q.

The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 ≤ n ≤ 10000. The subsequent n lines contain two integer numbers each which are the x and y coordinates of a point. Every point is unique and we have that -10000000 ≤ x, y ≤ 10000000.

For each set of input data print yes if the set of points has a center of symmetry and no otherwise.

Sample input

1
8
1 10
3 6
6 8
6 2
3 -4
1 0
-2 -2
-2 4

Output for sample input

yes


#include <stdio.h>
#include <map>
using namespace std;
long long x[10000], y[10000], avex, avey, n;
void solve() {
if(avex%n || avey%n) {
puts("no");
return;
}
avex /= n, avey /= n;
map<long long, int> r;
int i;
for(i = 0; i < n; i++)
r[x[i]*100000000+y[i]] = 1;
long long xx, yy;
for(i = 0; i < n; i++) {
xx = 2*avex - x[i];
yy = 2*avey - y[i];
if(r[x[i]*100000000+y[i]] == 0) {
puts("no");
return;
}
}
puts("yes");
}
int main() {
int t, i;
scanf("%d", &t);
while(t--) {
scanf("%lld", &n);
avex = 0, avey = 0;
for(i = 0; i < n; i++) {
scanf("%lld %lld", &x[i], &y[i]);
avex += x[i], avey += y[i];
}
solve();
}
return 0;
}

台長: Morris
人氣(1,005) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Math&DFS] 10012 - How Big Is It?
此分類上一篇:[UVA][Knuth'sPermutation] 110 - Meta-Loopless Sorts

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文