題意:
題意跟hdu1290是一樣的
切n刀最多可以把蛋糕分成多少份,注意直接2^n是錯的
仔細想想,問題轉化成N個平面最多可以把空間劃分成多少份,公式是fn=(n^3+5n)/6+1
數據比較大,記得用64位整數long long
代碼:
/*
* Author: NICK WONG
* Created Time: 2/14/2016 18:29:09
* File Name:
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
#define out(x) cout<<#x<<": "<<x<<endl
const double eps(1e-8);
const int maxn=10100;
const long long maxint=-1u>>1;
const long long maxlong=maxint*maxint;
typedef long long lint;
lint n;
void init()
{
}
void work()
{
lint ans=(n*n*n+5*n+6)/6;
cout<<ans<<endl;
}
int main()
{
while(cin>>n)
{
init();
work();
}
return 0;
}
推導過程
由二維的分割問題可知,平面分割與線之間的交點有關,即交點決定射線和線段的條數,從而決定新增的區域數。試想在三維中則是否與平面的交線有關呢?當有n-1個平面時,分割的空間數爲f(n-1)。要有最多的空間數,則第n個平面需與前n-1個平面相交,且不能有共同的交線。即最多有n-1 條交線。而這n-1條交線把第n個平面最多分割成g(n-1)個區域。(g(n)爲(1)中的直線分平面的個數 )此平面將原有的空間一分爲二,則最多增加g(n-1)個空間。
故:f=f(n-1)+g(n-1) ps:g(n)=n(n+1)/2+1
=f(n-2)+g(n-2)+g(n-1)
……
=f(1)+g(1)+g(2)+……+g(n-1)
=2+(1*2+2*3+3*4+……+(n-1)n)/2+(n-1)
=(1+2^2+3^2+4^2+……+n^2-1-2-3-……-n )/2+n+1
=(n^3+5n)/6+1
參考:
Total Submit: 8 Accepted: 2 Special Judge: No
as many pieces as possible with n cuts. But he cannot decide how to cut it, because the apple is rather delicious. Now he needs your help.
Input will be terminated by EOF.
Output
2
3
Sample Output
4
8
Hint
Source