zoukankan      html  css  js  c++  java
  • HDU 2050:折线分割平面

    折线分割平面

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


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

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

     

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

     

    Sample Input
    2 1 2
     

    Sample Output
    2 7

    分割平面数=交点数 + 顶点数 + 1

    每增加一条折线,顶点数增加1,交点数增加4*(n-1)。即a(n)=a(n-1)+4*(n-1)+1

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <math.h>
    #include <limits.h>
    #include <map>
    #define ll long long
    #define INF 0x3f3f3f3f
    const int maxn=1e4+10;
    int a[maxn];
    int main(int argc, char const *argv[])
    {
    	a[1]=2;
    	for(int i=2;i<maxn;i++)
    	{
    		a[i]=a[i-1]+4*(i-1)+1;
    	} 
    	int n;
    	int t;
    	std::cin>>t;
    	while(t--)
    	{
    		std::cin>>n;
    		std::cout<<a[n]<<std::endl;
    	}
    	return 0;
    }
  • 相关阅读:
    java中栈内存和堆内存的简单理解
    java中构造函数与一般函数的区别

    另一部漫画
    海边的卡夫卡
    11-12
    这篇大概值一百万吧
    我的千岁寒
    11-9
    嗯……………股票已经涨的我不想上班了
  • 原文地址:https://www.cnblogs.com/Friends-A/p/9308993.html
Copyright © 2011-2022 走看看