【題解】Codeforces 1300D. Aerodynamic

【題目敘述】http://codeforces.com/contest/1300/problem/D

#include <iostream>
using namespace std;
 
int n, x[100005], y[100005];
 
int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    if (n % 2 == 1){
        cout << "NO\n";
        return 0;
    }
    int tmp = n / 2, i, j;
    bool flag = true;
    for (i = 0; i < tmp-1; i++){
        j = i + tmp;
        if (abs(x[i]-x[i+1])!=abs(x[j]-x[j+1]) || abs(y[i]-y[i+1])!=abs(y[j]-y[j+1])){
            flag = false;
            break;
        }
    }
    i = tmp-1;
    j = i + tmp;
    if (abs(x[i]-x[i+1])!=abs(x[j]-x[0]) || abs(y[i]-y[i+1])!=abs(y[j]-y[0])){
        flag = false;
    }
    if (flag) cout << "YES\n";
    else cout << "NO\n";
}
分享本文 Share with friends