2016huasacm暑假集训训练四 递推_B

题目链接:https://vjudge.net/contest/125308#problem/B

题意:给定n个三角形,问最多可以把区域化成多少个部分,这是一个一维空间  一定会满足一元二次方程  题目给定1 2的个数 只要得到3的个数就可以用待定系数法求得公式:F(x) = 3*(x-1)*x+2;  另外如果是二维的话,会满足一元三次方程 ,也可以用待定系数法求解;20

AC代码:

 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStream;
 4 import java.io.InputStreamReader;
 5 import java.io.PrintWriter;
 6 import java.util.StringTokenizer;
 7 
 8 public class Main {
 9     public static void main(String[] args) {
10         InputReader s = new InputReader(System.in);
11         PrintWriter cout = new PrintWriter(System.out);
12         int t , x,t1;
13         t  =   s.nextInt();
14         while (t-- > 0) {
15             x = s.nextInt();
16              t1 = 3*(x-1)*x+2;
17             cout.println(t1);
18          
19         }
20         cout.flush();
21     }
22     static int gcd(int a, int b) {
23         return b == 0 ? a : gcd(b, a % b);
24     }
25 }
26 class InputReader {
27 
28     public BufferedReader rea;
29     public StringTokenizer tok;
30 
31     public InputReader(InputStream stream) {
32         rea = new BufferedReader(new InputStreamReader(stream), 32768);
33         tok = null;
34     }
35 
36     public String next() {
37         while (tok == null || !tok.hasMoreTokens()) {
38             try {
39                 tok = new StringTokenizer(rea.readLine());
40             } catch (IOException e) {
41                 throw new RuntimeException(e);
42             }
43         }
44         return tok.nextToken();
45     }
46 
47     public int nextInt() {
48         return Integer.parseInt(next());
49     }
50 
51 }
原文地址:https://www.cnblogs.com/LIUWEI123/p/5743511.html