hdu2050:折线分割平面

http://acm.hdu.edu.cn/showproblem.php?pid=2050

Problem Description

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

 

 

Input

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

 

 

Output

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

 

 

Sample Input


 

2

1

2

 

 

Sample Output


 

2

7

 

 

#include<stdio.h>
#define N 10020
long long a[N];
int main()
{
	int t,n,i;
	a[1]=2;
	a[2]=7;
	for(i=3;i<N;i++)
		a[i]=a[i-1]+4*(i-1)+1;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		printf("%lld\n",a[n]);	
	}
	return 0;
} 

 

 

#include<stdio.h>
int main()
{
    long long n;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        printf("%lld\n",2*n*n-n+1);    
    }

    return 0;
} 

 

 

posted @ 2018-10-19 13:21  宿星  阅读(116)  评论(0编辑  收藏  举报