思路: 考虑到每次必须在o(1)的复杂度下计算出答案,该题肯定就是推出一个关于n的一元几次式。因此打表找规律。
打表后
得到1,5,15,35,70,126,210..
作差 4, 10, 20, 35, 56, 84
作差 6, 10, 15, 21, 28
再作差 4,5,6,7
再做差1,1,1,1
共做差四次 因此设 f(n)=a∗n4+b∗n3+c∗n2+d∗n+eAn=a∗n4+b∗n3+c∗n2+d∗n+e
求解出系数即可
打表代码:
#include <bits/stdc++.h>
using namespace std;
struct Node
{
double x,y;
}node[10022];
double dist(int x,int y){
return (node[x].x-node[y].x)*(node[x].x-node[y].x)+(node[x].y-node[y].y)*(node[x].y-node[y].y);
}
int main()
{
double pp=10;
for(pp=1;pp<=10;pp++){
int num=1;
node[1].x=0;node[1].y=(double)(pp)*sqrt(3);
int i;
for(i=2;;){
if(num%2){
for(int j=1;j<=num;j