D. ant plane

D. ant plane

A single point of time: 2.0 sec

Memory Limit: 512 MB

There are a plane  n ants, it can be regarded as the path traveled in a straight line

By these n  certain regions defined straight lines is unbounded, while other regions are bounded.

The maximum number of bounded region is how much?

Example, there are four straight lines, only the following bounded region leftmost figure is the largest line defined

2

Input Format

T  set of inputs,  ( . 1 T 100 )

Each a number of  n-  , ( . 1 n- 10 . 9 )

Output Format

For each test, it outputs a maximum integer number of bounded areas.

Sample

input
1
4
output
3
 Similar problems are summarized:

1 Title: n straight line, a plane can be divided into a maximum number of regions.

    Formula: B (n) = n (n + 1) / 2 + 1, or F (n) = F (n-1) + n

has a plane of X n type unknown object, such that the plane formed by division as much as possible

  Formula   f = N (2N + 1) +1

 

3  . Division planes polyline

Can be seen from the figure, an extra fold line each, a plurality will be 4 * (n-1) points of intersection, will be more than that is 4 * (n-1) +1 planar, then we can get the recursive formula:

       f [n] = f [n-1] + 4 * (n-1) +1 or 2 * n ^ 2-n + 1

 

 

 

 
 
 

Guess you like

Origin www.cnblogs.com/Accepting/p/11297205.html
ANT
ANT