【简单几何】CF Edu11 D

Problem - D - Codeforces

题意:

【简单几何】CF Edu11 D_第1张图片

思路:

和蓝桥杯国赛有道题类似,都是用中点来确定图形防止精度缺失

应该算是典

【简单几何】CF Edu11 D_第2张图片 

Code:

#include 

using i64 = long long;

constexpr int N = 2e3 + 10;
constexpr int M = 1e6 + 10;
constexpr int P = 2600;
constexpr i64 Inf = 1e18;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-6;


int n;
int x[N], y[N];

void solve() {
    std::cin >> n;
    for (int i = 1; i <= n; i ++) std::cin >> x[i] >> y[i];

    std::map ,int> mp;
    for (int i = 1; i <= n; i ++) {
        for (int j = i + 1; j <= n; j ++) {
            int a = x[i] + x[j];
            int b = y[i] + y[j];
            mp[{a, b}] ++;
        }
    }

    int ans = 0;
    for (auto t : mp) {
        int cnt = t.second;
        int k = cnt * (cnt - 1) / 2;
        ans += k;
    }

    std::cout << ans << "\n";
}
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

 

你可能感兴趣的:(几何,算法)