P2181 Diagonal [Permutation and Combination | Mathematics]

Subject: https://www.luogu.com.cn/problem/P2181

Question: Give an n-sided shape, connect all the diagonals, and ask how many intersections there are in total.

Solution: Seeing a pretty good understanding, two lines will have a focus, then reflected on the n-sided shape, that is, four points will have an intersection, so the question becomes to choose any four points, how many Kind of method?

#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;
}

Guess you like

Origin blog.csdn.net/Mercury_Lc/article/details/107968184