NAIPC 2019 A

学习:https://blog.csdn.net/qq_21334057/article/details/99550805

题意:从n个点中选择k个点构成多边形,问期望面积。

题解:如果能够确定两个点,那么可以从这两个点之间选择k−2个点来构成一个k边形。所以可以枚举两个点,计算这两个点被选入构成凸包的概率和对凸包贡献的面积。

#include <bits/stdc++.h>
#define fopi freopen("in.txt", "r", stdin)
#define fopo freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef long double ld;
const int maxn = 2500 + 10;

struct Point {
    ld x, y;
}a[maxn];

ld C[maxn][maxn];

void getC(int n) {
    C[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++)
            C[i][j] = C[i-1][j] + C[i-1][j-1];
    }
}

ld Cross(Point a, Point b) {
    return a.x*b.y - a.y*b.x;
}

int n, k;
int main() {
    ios::sync_with_stdio(false);

    cin >> n >> k;
    getC(n);

    for (int i = 1; i <= n; i++)
        cin >> a[i].x >> a[i].y;

    ld ans = 0;
    for (int i = 1; i <= n; i++)
    for (int j = k-1; j <= n-1; j++) {
        int t = i+j;
        if (t > n) t -= n;
        ans += Cross(a[i], a[t]) * C[j-1][k-2] / C[n][k];
    }
    
    printf("%.7Lf
", ans/2);
}
View Code
原文地址:https://www.cnblogs.com/starve/p/11619952.html