HDU-2050-Polyline split plane

Polyline split plane




Problem Description

We have seen many problems of dividing planes by straight lines. Today's problem is slightly changed. What we require is the maximum number of planes divided by n polylines. For example, a polyline can divide the plane into two parts, and two polylines can divide the plane into up to 7 parts, as shown below.
 

Input

The first line of the input data is an integer C, which represents the number of test instances, followed by C lines of data, each line contains an integer n (0<n<=10000), which represents the number of polylines.

 

Output

For each test instance, output the maximum number of splits for the plane, one line per instance.

 

Sample Input

 
  
2
1
2
 

Sample Output
 
  
2
7

1 Recursion, first analyze the situation of dividing the plane by a straight line. When adding the nth straight line, there will be at most n-1 intersections with the previous straight line, and at this time, there are more parts divided.

      (n-1)+1;

     The same is true for the 2-fold line, f(1)=2, f(2)=7, first draw the first n-1 broken lines, when the nth line is added, the new intersection with the graph is at most 2* 2(n-1), so the divided part is more than 2*2(n-1)+1, so f(n)=f(n-1)+4*(n-1)+1, n>=3



#include<bits/stdc++.h>
using namespace std;
intmain()
{
    long long int a[10005];
    a[1]=2;
    for(int j=2;j<=10005;j++)
    {
        a[j]=a[j-1]+4*(j-1)+1;
    }
    int n,k;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&k);
        printf("%lld\n",a[k]);
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324439176&siteId=291194637