Hdoj 2050. Polyline Split plane

Source: Internet
Author: User
Tags polyline

Problem Description

We've seen a lot of straight-line split-plane problems, and this topic is slightly different today, and we're asking for the maximum number of n-polyline split planes. For example, a polyline can divide the plane into two parts, and a maximum of two polylines can be divided into 7 parts, as shown below.

Input

The first line of the input data is an integer c, representing the number of test instances, followed by the C row of data, each line containing an integer n (0<n<=10000), representing the number of polylines.

Output

For each test instance, output the maximum number of partitions for the plane, and the output for each instance takes up one row.

Sample Input

212

Sample Output

27

Author

Lcy

Source

Recursive solution topic exercise (for beginner)

Ideas

First consider the case of a straight line, the nth line produces a maximum of \ (n-1\) intersection, the portion of the split is increased by \ (() (N-1) +1 = n\)

Now look at the polyline can be understood as 2 straight lines:

    • One and the other part of the polyline ( (N-1) \), is \ (N-1) \), the polyline has 2 lines, that is, the final answer is up to \ (2*2* (N-1) \) the intersection, more increase \ (2*2* (N-1) +1\) Parts

So the recursive type is:\ (F[i] = f[i-1] + (i-1) + 1;\)

Initial conditions:\ (f[1]=2\)

Code

#include<bits/stdc++.h>using namespace std;__int64 f[10010];int main(){    int t;        f[1] = 2; f[2] = 7;    for(int i=3;i<=10000;i++)        f[i] = f[i-1] + 4*(i-1) + 1;        cin >> t;    while(t--)    {        int tmp;        cin >> tmp;         cout << f[tmp] << endl;    }    return 0;   }

Hdoj 2050. Polyline Split plane

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.