HDOJ1290解题报告【找规律】

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1290

题目概述:

  在空间中插入n个平面,最多将空间分成几个部分?

大致思路:

  很容易看出是找规律的题,最开始想的规律是:

    切n刀分出最多的蛋糕块数=(n-1刀将平面分出的最多块数)*2

  不过很显然错了,因为根本给不出严谨的数学证明。

  后来上网学习了一波发现了找规律题的规律:

       三维的公式一般为三次多项式,二维的公式一般为二次多项式

  然后待定系数法就可以了。

  等我数学能力强了再证明吧……

复杂度分析:

  求除了数学公式之后复杂度即为O(T),其中T为数据组数。 

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <vector>
 5 #include <ctime>
 6 #include <queue>
 7 #include <cstring>
 8 #include <algorithm>
 9 using namespace std;
10 
11 #define sacnf scanf
12 #define maxn 1010
13 #define inf 0x7fffff
14 #define Eps 0.001
15 void Swap(int &a,int &b) {int t=a;a=b;b=t;}
16 typedef long long ll;
17 typedef unsigned int uint;
18 
19 int f[maxn];
20 
21 int main()
22 {
23     //freopen("data.in","r",stdin);
24     //freopen("data1.out","w",stdout);
25     int n;
26     while(~scanf("%d",&n))
27     {
28         printf("%d
",(n*n*n+5*n+6)/6);
29     }
30     return 0;
31 }
原文地址:https://www.cnblogs.com/CtrlKismet/p/6119935.html