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*n+5*n+6)/6);
29     }
30     return 0;
31 }

 

转载于:https://www.cnblogs.com/CtrlKismet/p/6119935.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值