ZJANS

b604. Center of Symmetry

Medium Last Update: 2026/01/18
數學

č§Ŗæŗ•ä¸€ã€æ•¸å­¸

🔹 č¨ˆįŽ—ä¸­åŋƒéģž

č¨ˆįŽ—ä¸­åŋƒéģžåžŒ 再將每個éģžå¸ļå›žéŠ—įŽ—

å…Ŧåŧ

中åŋƒéģž
M(x,y)=(x1+x2+...+xnn,y1+y2+...+ynn)M(x, y) = (\frac{x_{1} + x_{2} + ... + x_{n}}{n}, \frac{y_{1} + y_{2} + ... + y_{n}}{n})

尋扞對應éģž
Q=M+PM→Q = M + \overrightarrow{PM}
        =P+2PM→\;\;\;\; = P + 2\overrightarrow{PM}
        =P+2(M−P)\;\;\;\; = P + 2(M-P)
        =2M−P\;\;\;\; = 2M - P

x1+x2+...+xnn\frac{x_{1} + x_{2} + ... + x_{n}}{n} 可čƒŊ不是整數īŧŒå…ˆ *2 再 /n

✅ 厌整äģŖįĸŧ

čŠ•åˆ†įĩæžœ(åƒč€ƒ) īŧš AC (5ms, 972KB)

#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    while(true){
        cin >> n;
        if(n == 0) break;
        
        double mx=0, my=0;
        set<pair<int, int>> p;
        for(int i=0; i<n; i++){
            int x, y;
            cin >> x >> y;
            p.insert({x, y});
            mx += x;
            my += y;
        }
    
        mx = mx*2/n;
        my = my*2/n;
    
        string ans = "yes";
        for(auto& a : p){
            if(!p.count({mx-a.first, my-a.second})){
                ans = "no";
                break;
            }
        }
        
        cout << ans << "\n";
    }
    
    return 0;
}