折线分割平面
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35975 Accepted Submission(s): 24105
Problem Description
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。
![](http://acm.hdu.edu.cn/data/images/C40-1008-1.jpg)
Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。
Output
对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
Sample Input
212
Sample Output
27
本题依旧是递归结题,重点是找递归表达式,找出第n项与第n-1项或者第n-2项的关联即可。
详细的结题思路请参考:
https://blog.csdn.net/xia842655187/article/details/47043361
https://www.jianshu.com/p/18ed6a125e82
import java.util.Scanner;
public class P2050 {
public static void main(String[] args) {
long a[] = new long[10050];
a[1] = 2;
a[2] = 7;
for (int i = 3; i <=10000; i++) {
a[i] = a[i - 1] + 4 * i - 3;
}
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int c = sc.nextInt();
while (c-- > 0) {
int n = sc.nextInt();
System.out.println(a[n]);
}
}
}
}