hdu2050折线分割平面

我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。
Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。 Output对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
Sample Input
2
1
2
Sample Output
2
7

由直线分割平面推来:Ln=Ln-1+n
可以看作两条共顶点射线,则这两条射线比直线少2,n条少2n
Vn=L2n-2n
  =Vn-1+4n-3;
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e4+5;
 4 const int INF=1e9+7;
 5 int c,n;
 6 long long f[maxn];
 7 template <class t>void red(t &x)
 8 {
 9     x=0;
10     int w=1;
11     char ch=getchar();
12     while(ch<'0'||ch>'9')
13     {
14         if(ch=='-')
15             w=-1;
16         ch=getchar();
17     }
18     while(ch>='0'&&ch<='9')
19     {
20         x=(x<<3)+(x<<1)+ch-'0';
21         ch=getchar();
22     }
23     x*=w;
24 }
25 void input()
26 {
27     freopen("input.txt","r",stdin);
28 }
29 int main()
30 {
31     //input();
32     red(c);
33     f[1]=2;
34     f[2]=7;
35     for(int i=3;i<=10000;++i)
36         f[i]=f[i-1]+4*i-3;
37     while(c--)
38     {
39         red(n);
40         printf("%lld\n",f[n]);
41     }
42     return 0;
43 }
View Code

 

 
posted @ 2019-04-26 18:01  Achen_sy  阅读(204)  评论(0编辑  收藏  举报