zoukankan      html  css  js  c++  java
  • hdu 2050 折线分割平面 dp递推 *

    折线分割平面

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


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

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

     
    Sample Input
    2
    1
    2
     
    Sample Output
    2
    7
     
    Author
    lcy
     
    Source

    思路: 
    第n条折线应该与前n-1条折线的两条边都相交时交点最多,由于该折现与每条折线的两条边分别有两个交点,每个交点都分割出一条线段(端点处为射线),所以此时有4*(n-1)条线段和两条射线,但是端点处两条线段相交,因此还要减去1。状态转移方程为:dp[n] = dp[n - 1] + 4 * (n - 1) + 2 - 1

    参考:http://blog.csdn.net/wyk19950704/article/details/50429420?locationNum=10&fps=1

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    #define maxn 10010
    int main()
    {
        int n,T;
        long long dp[maxn];
        dp[1] = 2;
        for(int i=2;i<=10010;i++){
            dp[i] = dp[i-1] + 4*(i-1) + 2 - 1;
        }
        while(cin >> T){
            while(T--){
                cin >> n;
                cout << dp[n] << endl;
            }
        }
        return 0;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    优先队列
    Problem W UVA 662 二十三 Fast Food
    UVA 607 二十二 Scheduling Lectures
    UVA 590 二十一 Always on the run
    UVA 442 二十 Matrix Chain Multiplication
    UVA 437 十九 The Tower of Babylon
    UVA 10254 十八 The Priest Mathematician
    UVA 10453 十七 Make Palindrome
    UVA 10163 十六 Storage Keepers
    UVA 1252 十五 Twenty Questions
  • 原文地址:https://www.cnblogs.com/l609929321/p/7224067.html
Copyright © 2011-2022 走看看