hdu---2050---折线分割平面

http://acm.hdu.edu.cn/showproblem.php?pid=2050

解题思路:1.递推递推,先分析下直线分割平面的情况,增加第n条直线的时候,跟之前的直线最多有n-1个交点,此时分出的部分多出了

      (n-1)+1;

     2.折线也是同理,f(1)=2,f(2)=7,先画好前面n-1条折线,当增加第n条拆线时,此时与图形新的交点最多有2*2(n-1)<相当于4条射线相交多出来的>个,

      所以分出的部分多出了2*2(n-1)+1   所以推出f(n)=f(n-1)+4*(n-1)+1,n>=3

 

折线分割平面

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25649    Accepted Submission(s): 17440

Problem Description

 

我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。

 

 


Input

 

输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。

 

 


Output

 

对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。

 

 


Sample Input

 

2 1 2

 

 


Sample Output

 

2 7

 

 


Author

 

lcy

 

 


Source

 

 

 


Recommend

 

lcy   |   We have carefully selected several similar problems for you:  2046 2045 2044 2049 2041 
 
 
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define PI 3.1415926

const int maxn=10007;///注意,被Wa了一次
const int INF=0x3f3f3f3f;

long long a[maxn];

int main()
{
    int T;
    scanf("%d", &T);
    a[1]=2;
    a[2]=7;

    for(int i=3; i<maxn; i++)
        a[i]=a[i-1]+4*(i-1)+1;
    while(T--)
    {
        int n;
        scanf("%d", &n);

        printf("%lld\n", a[n]);
    }
    return 0;
}

 

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define PI 3.1415926

const int maxn=1007;
const int INF=0x3f3f3f3f;

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        printf("%d\n", 2*n*n-n+1);
    }
    return 0;
}
View Code

 

 

posted @ 2016-08-08 10:35  爱记录一切美好的微笑  阅读(277)  评论(0)    收藏  举报