Splitting plane
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
2
-
描述
-
We have seen many problems about straight line splitting plane.Today ours problem has little difference with before.Because this time we don't use a straight line to splitting plane,we use a broken line to splitting plane.
For example , a broken line can divided a plane to two parts, two broken line can divided a plane to seven parts.
-
输入
-
The first line input an integer N(1<N<10000)
Then N trip test data
Each test data have a integer M. M represents the number of broken lines.(0<M<=10000)
输出
- For each test case, please output plane's biggest segmentation number, the output of each instance of one line.
-
The first line input an integer N(1<N<10000)
令f(n-1)为前n-1条折线分割的平面数,当添加第n条折线时。
因为每一条边与前n-1条折线的两条边都相交,故增加的交点数为2*2*(n-1),顶点增加1,故
f(n)=f(n-1)+4(n-1)+1运用递归即可求出:
代码如下:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<assert.h>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iterator>
#include<map>
#include<cmath>
using namespace std;
int f(int n)
{
if(n==0)
{
return 1;
}
if(n==1)
{
return 2;
}
return f(n-1)+4*(n-1)+1;
}
int main()
{
int n;
cin>>n;
while(n--)
{
int m;
cin>>m;
cout<<f(m)<<endl;
}
}