题目大意
原题链接:HDOJ 2050 折线分割平面
解题思路
f(1)=2;
f(2)=7;
:
f(n)=f(n-1)+4*(n-1)+1;
每多加一条折线最多与前面n-1条折线有4*(n-1)个交点,而分割的区域比前一次多4*(n-1)+1个。
代码实现
#include<bits/stdc++.h>
using namespace std;
int f(int x)
{
if(x==1)
return 2;
else
return f(x-1)+4*(x-1)+1;
}
int main()
{
int C;
cin>>C;
while(C--){
int n;
cin>>n;
cout<<f(n)<<endl;
}
return 0;
}