Polyline division plane
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35192 Accepted Submission(s): 23630
Solution: first discuss the issue straight division planes. If n = 1, a [1] = 2; n = time 2, a [2] = 4; n = 3 when, a [3] = 6; when n = n, order to share up plane, this straight line must intersect a straight line as much as possible, i.e. the n-1 intersects with a straight line, then this straight line is split into two rays and n-2 line segments. Therefore, a [n] = a [n-1] + n-2 + 2; i.e., a [n] = a [n-1] + n;
Then talk about this question, while if n = 1, a [1] = 2; when n = time 2, n = 7; if n = n, the plane in order to share up, the two rays polyline edges to the same as many lines intersect, i.e. for each ray and 2 * (n-1) lines intersecting two rays is 2 * 2 * (n-1); in this case, the newly generated 2 * 2 * (n-1) +1 th surface;
That is: a [n] = a [n-1] + 4 * (n-1) +1;
code show as below:
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10005];
int main()
{
int t;
a[1]=2;
for(int i=2;i<=10000;i++)
a[i]=a[i-1]+4*(i-1)+1;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
printf("%d\n",a[n]);
}
return 0;
}