Polyline division plane recursion and common line division and polyline division summary

Polyline split plane

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36381    Accepted Submission(s): 24376


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. For the straight line to divide the plane, the rule satisfied is: 1+(n+1)*n/2;

2. For two parallel lines to divide the plane, the rule satisfied is: 2*n*n+1;

3. For the dividing plane by the polyline, the following rule is: 2*n*n+1-n;

For specific content, refer to: http://blog.sina.com.cn/s/blog_76eabc150100swg8.html

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int c;
    int n;
    cin>>c;
    while(c--)
    {
        cin>>n;
        long long num=0;
        num=2*n*n+1-n;
        cout<<num<<endl;
    }
    return 0;
}

Guess you like

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