"NEUQACM OJ" 1017: Plane Cut (special edition)

Source: Internet
Author: User
Tags polyline

1017: plane cut (special edition)Title Description

We are asking for the maximum number of N lightning-type polyline split planes. For example, a lightning-type polyline can divide the plane into two parts, two can divide the plane into 12 parts, three can divide the plane into 31 parts, and four can divide a plane into 59 parts.

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
3123
Sample Output
21231
Tips

Notice the recursive way to find the mathematical formula Oh ~

The consistent data is more, and the topic hint uses the recursive mathematics formula, namely the mathematics recursive formula;

Let's analyze the array of known groups

When the Lightning star Polyline is n=1, the plane is divided into c=2 parts.

n=2 c=12 situation

There are the first two sets of data, and the geometry, can infer, n each increase 1,c increase with n positive correlation, that is, the increment of C each time is on the basis of the previous C value of the addition of a specific value, that is, before and after two non-multiple relations

The following assumes a recursive formula c[i]=c[i-1];

Let's take the data from the topic below.

n=2;

C[2]=c[1]=2 and actual c[2]=12; The former less 1*10-0;

n=3;

C[3]=c[2]=12 and actual c[3]=31; The former less 2*10-1;

n=4;

C[4]=c[3]=31 and actual c[4]=59; The former less 3*10-2;

.

.

.

.

It is easy to get the correct recursive formula for c[i]=c[i-1]+10* (i-1)-(i-2);

The recursive formula comes out and the following code is posted:

1#include <iostream>2 using namespacestd;3 inta[10001];4 voidlist ()5 {6a[1]=2;7      for(intI=2; i<=10000; i++)8     {9a[i]=a[i-1]+ (I-1)*Ten-(I-2);Ten     } One } A intMain () - { -     intN,n; theCin>>N; - list (); -      while(n--) -     { +Cin>>N; -cout<<a[n]<<Endl; +     } A      at     return 0; -}

2016-06-05-17:51:21

"NEUQACM OJ" 1017: Plane Cut (special edition)

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.