zoukankan      html  css  js  c++  java
  • 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
    ", 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
    ", 2*n*n-n+1);
        }
        return 0;
    }
    View Code

     

  • 相关阅读:
    20162330 2016-2017-2《程序设计与数据结构》课程总结
    强化学习--Policy Gradient
    59. Spiral Matrix II
    54. Spiral Matrix(剑指offer 19)
    58. Length of Last Word
    c++ string split
    神经网络反向传播,通俗理解
    大话设计模式C++ 备忘录模式
    57. Insert Interval
    c++ sort
  • 原文地址:https://www.cnblogs.com/w-y-1/p/5748069.html
Copyright © 2011-2022 走看看