woj1034 hdu1290 Cut the Apple 數學題

題意:

題意跟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


參考:

分割平面與空間公式

Cut the Apple
Time Limit: 1000MS   Memory Limit: 65536KB  Difficulty: 3
Total Submit: 8  Accepted: 2  Special Judge: No
Description
On the way home, DragonFly has got an extraordinarily large apple. He would like to share it with his friends. Now he wants to get
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
    Each line contains an integer n (0<= n <= 100000).
    Input will be terminated by EOF.

Output
    You should print the largest number of pieces by n cuts of each case .
Sample Input
1
2
3

Sample Output
2
4
8

Hint

Source
WHUCPC04 Final Round 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章