折线划分平面

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.
分割平面的个数=交点个数+顶点个数+1
令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;
   }
    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值