hdu 2050:折线分割平面(水题,递归)

折线分割平面

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13355    Accepted Submission(s): 9247

Problem Description
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。
hdu 2050:折线分割平面(水题,递归)
Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。
Output
对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
 
Sample Input
2
1
2
Sample Output
2
7
 
Author
lcy
 
Source
Recommend
lcy
 

  水题,递归。
  一道标准递归题。
  递推公式:
  hdu 2050:折线分割平面(水题,递归)
 
Code:
 1 Problem : 2050 ( 折线分割平面 ) Judge Status : Accepted  2 RunId : 8926790    Language : G++ Author : freecode  3 Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta  4 #include <iostream>

 5 using namespace std;  6 

 7 int f(int n)  8 {  9     if(n==1) 10         return 2; 11     else

12         return f(n-1)+4*(n-1)+1; 13 } 14 

15 int main() 16 { 17     int C,n; 18     cin>>C; 19     while(C--){ 20         cin>>n; 21         cout<<f(n)<<endl; 22  } 23     return 0; 24 }

 

Freecode : www.cnblogs.com/yym2013

你可能感兴趣的:(HDU)