FOJ1091 Zig-Zag Lines

来源:互联网 发布:淘宝网雪纺胖妹妹长袖 编辑:程序博客网 时间:2024/04/28 09:30

What's the maximum number of regions definable by N zig-zag lines, each of which consists of two parallel infinite half-lines joined by a straight line segment?

Here is an example of 2 zig-zag lines yield 12 regions at the most.


Input

The input consists of a sequence of N (<= 10000), which is the number of the zig-zag lines, one per line.


Output

For each N, you should output the number of the maximum regions.


Sample Input

12

Sample Output

212

     

     这题看了N久,还是没找到递推关系,不过看了某大牛的的递推思想的确是妙:先将Z线斜线段看成直线处理,生成的区域数目H(n),H(1)=6;H(n+1)=H(n)+)+(3n+1)*2+(3n+3),(3n+1)是每条新增的平行线把前H(n)个区域划分的增加的数目,这时区域里直线的数目=3n+2,最后一条斜线使得区域增加的数目=3n+3。Z中斜线是线段的M(n),M(n)=G(n)-4n,因为,每个Z有两个角,如果斜线是直线,把每个角都补上对角,发现区域里会多出2*2*n块。

      M(n+1)=M(n)+9n+1.

 

 

 

声明:本博客内容并非原创,如涉侵权,请告知本人,将尽快删除。

原创粉丝点击