题意:一个圆上找n个点两两相连,要求划分的块数最多。
https://www.nowcoder.com/acm/contest/135/F(题目链接)
思路:显然,这是一道直线分平面的变形题,首先我们不管相连的情况,每增加一条直线,平面数最多增加为(与之相交直线数+1)
当n=0时,显然块数sum=1。
n=1,sum=f(0) + 1= 2;
n=2,sum=f(1) + (1 + 0)+ (1+(2 - 1 - 1)*(1 - 1)) = 4;
以此类推可以得到:
显然这个式子可以化简为:
通过连续自然数的平方和和直接加和的公式可以化简为:
通过递推得出:
又因为
可以推得:
最后附上python版代码(好像不用大数,c++unsign long long好像就够了)
# encoding: utf-8
while True:
try:
n = int(input())
ans = n * n * n * n + 23 * n * n - 6 * n * n * n - 18 * n
ans = int(ans / 24) + 1
print(ans)
except EOFError:
break;
c++的也附上一个吧
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 1e5 + 7;
const double ex = 1e-8;
typedef unsigned long long ull;
typedef long long ll;
typedef double dl;
int main()
{
ull n;
while(cin >> n){
ull ans = (n * n * n * n - 6 * n * n * n + 23 * n * n - 18 * n) / 24 + 1;
cout << ans << endl;
}
return 0;
}