P2181 对角线 【排列组合 | 数学】

题目:https://www.luogu.com.cn/problem/P2181

题意:给一个 n 边形,将所有对角线连起来,问一共有多少个交点。

题解:看到一个蛮好的理解,两条线会有一个焦点,那么反映在 n 边形上,就是四个点就会有一个交点,所以问题就变成了任取四个点,有多少种取法?

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    unsigned long long  n;
    scanf("%lld",&n);
    unsigned long long res = n * (n - 1) / 2 * (n - 2) / 3 * (n - 3) / 4;
    printf("%lld\n",res);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/107968184