• HDOJ_ACM_折线分割平面


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

                对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
     
    Sample Input
    2
    1
    2
     
    Sample Output
    2
    7
     
    Code
    View Code
    Key Points
    Fristly, it's the question which need inference.
    If it's straight line, it's easy for you to find out that f(n)=f(n-1)+(n-1)+1.
    Because when you add other straight line, it will increase n - 1 points, it means the number of surface will increase n.
    The same to broken line.
    When you add other broken line, it will add no more than 4(n-1) points, then the number of surface will increase 4(n-1)+1.
    Consequently, you will get the formula: f(n)=f(n-1)+4n-3.
    Secondly, according the formula, you can get another formula f(n)=2n^2-n+1 to simplify the code.
     
     
  • 相关阅读:
    栈和队列
    数组的遍历查找
    字符串的子串
    两个字符串
    字符串的遍历
    字符串的替换
    数组和矩阵
    Django 自带的ORM增删改查
    what's the CRSF ??
    Rabbitmq -Publish_Subscribe模式- python编码实现
  • 原文地址:https://www.cnblogs.com/chuanlong/p/2762448.html
Copyright © 2020-2023  润新知