hdu 2050折线分割平面(递推找规律)

Problem Description
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。
 

Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。

 

Output
对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。

 

Sample Input
  
  
2 1 2
 

Sample Output
  
  
2 7
f(n) = f(n-1) + 2*(n-1) + ( 2*(n-1) + 1 )

2*(n-1)  表示新加入的折线 把 已经存在的 2*(n-1)条边分割成 2*(n-1)个平面. (即上图的 1,2)

( 2*(n-1) + 1 ) 表示新加入的折线被分割所得的平面。由于前面n-1个折线有2*(n-1)条线。(即上图中的 3,4,5)

f(n-1) 即上图的 6,7

//
//  main.cpp
//  160929
//
//  Created by 刘哲 on 17/4/13.
//  Copyright © 2016年 my_code. All rights reserved.
//
//#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <stack>
#define lowbit(x) (x&-x)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        long long ans = 2*n*n-n+1;
        cout<<ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值