Luogu P2181 对角线


Luogu P2181 对角线

解析

  • 法一:每 4 个顶点会有一个交点,答案为 $ C_n^4 $
  • 法二:递推做差找规律

Code

法一

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
using namespace std;
ULL n;
int main()
{
	scanf("%llu",&n);
	printf("%llu\n",n*(n-1)/2*(n-2)/3*(n-3)/4);
	return 0;
}

法二

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const int N=1e5+5;
int n;
LL a[N],b[N],c[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		a[i]=a[i-1]+i;
		b[i]=b[i-1]+a[i];
		c[i]=c[i-1]+b[i];
	}
	printf("%lld\n",c[n-3]);
	return 0;
}
posted @ 2019-09-19 16:40  Hawking_llfz  阅读(100)  评论(0编辑  收藏  举报