Problem Description

對任意正整數n,空間中的n 個平面最多可將空間切成幾個區域?

Input Format

none

Output Format


none

Sample Input

1
2

Sample Output

2
4


-----*Problem from【ZeroJudge, An Online Judge System For Beginners

 

My Answer

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
#include<iostream>
using namespace std;
int cut(int n)
{
   if(n==1) return 2;
   else return cut(n-1)+((n*n-n+2)/2);
}
int main(void)
{
   int n;
   while(cin>>n){
      cout<<cut(n)<<endl;
   }
   return 0;
}


 


arrow
arrow
    全站熱搜

    兔老大 發表在 痞客邦 留言(2) 人氣()