HDU- fold line dividing plane (recursive)

Discounted division plane:

Problem Description

We've seen a lot of straight division title plane, today's change the subject slightly, we ask for is the n fold line dividing the maximum number of planes. For example, a fold line may be divided into two planar, two folds up into the planar portion 7, as shown below.

Input

The first line of input data C is an integer, indicates the number of test cases, then the C line data, each line contains an integer n (0 <n <= 10000), represents the number of fold lines.
Here Insert Picture Description

Output

For each test instance, the maximum division number output plane, the output of each row for instance.

Sample Input
2
1
2
Sample Output
2
7

Recursive analysis:
1. look at the situation straight division:

A line dividing two faces, two straight four faces, to make the maximum number of division plane, and the third should be the n-1 before the intersection (three lines intersect at one point, of course not be used), so, increasing the n straight lines n-1 increases intersections (we can try their drawing), increasing the n intersection points will increase the surface of n + 1, so that a [n] = (n * n + n + 2) / 2 (n is number line, a [n] is the number of planes).

2, for dividing a set of parallel lines, satisfy: 2 * ^ n-2 +. 1;

3, for a polyline, satisfy: A [n-] = ^ 2 * n-2-n-+. 1 (easily found, as compared to the case where the parallel lines, it is a more -n, since the fold line of one end of two parallel lines intersect each parallel line intersects the surface of a decrease, i.e., n sets of fold line parallel line is reduced compared to the n-th surface).

#include<stdio.h> 
int main()
{
	 int c;
	 long long a[10005];
	 scanf("%d",&c);
	 while(c--)
	 {
	  int n;
	  scanf("%d",&n);
	  
	  for(int i=1;i<=n;i++)
	   a[i]=2*n*n-n+1;
	   
	  printf("%lld\n",a[n]);
	 }
}

Summary:
dividing plane types:

1, the linear type: A [n-] = (n- n-n-+ + 2) / 2;
2, parallel line: F (n-) = 2N ^ 2 + 1;
. 3, broken line: F (n-) 2 =
n- 2-n-+. 1 ^;
. 4, the Z-shaped: f [n] = f [ n-1] + 9 * (n-1) +1
other recursive Title:
bull beef string EOF
God, God and God

Published 34 original articles · won praise 85 · views 4628

Guess you like

Origin blog.csdn.net/weixin_45895026/article/details/103840047