• SRM547


    1、

    Problem Statement

         You are given a int length. We have a regular hexagon: a polygon with six sides, in which all internal angles have 120 degrees and length is the length of each side. We are going to draw three non-intersecting diagonals in some way. These will divide the hexagon into four triangles. We will then compute their areas, take a piece of paper and write down the smallest of those four areas. Compute and return the largest number we can obtain on our piece of paper (by choosing which diagonals to draw).

    Definition

        
    Class: MinimalTriangle
    Method: maximalArea
    Parameters: int
    Returns: double
    Method signature: double maximalArea(int length)
    (be sure your method is public)
        
     

    Notes

    - Your return value must have a relative or an absolute error of less than 1e-9.

    Constraints

    - length will be between 1 and 1,000,000 (10^6), inclusive.

    Examples

    0)  
        
    5
    Returns: 10.825317547305485
     
    1)  
        
    10
    Returns: 43.30127018922194
     
    2)  
        
    100000
    Returns: 4.330127018922194E9
     

    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.    

    -

    public double maximalArea(int L){

    return (double)L/4.0*L*Math.sqrt(3);

    }

    2、

    Problem Statement

         On a horizontal line, there are N uniformly spaced vertical pillars. The pillars are numbered 0 through N-1, in order. For each i, the distance between the bottoms of pillars i and i+1 is exactly w. For each i, the height of pillar i (0-based index) is an integer between 1 and heights[i], inclusive. We want to take a single piece of rope and use it to join the top ends of all pillars, in order. (Once in place, the rope will have the shape of a polyline consisting of N-1 segments.) What is the shortest length of rope that is guaranteed to be sufficient, regardless of the actual pillar heights? You are given the int[] heights and the int w. Compute and return the answer to the above question. In other words, find a sequence of pillar heights (within the given constraints) for which the length of the rope we need is maximized, and return that maximum.

    Definition

        
    Class: PillarsDivTwo
    Method: maximalLength
    Parameters: int[], int
    Returns: double
    Method signature: double maximalLength(int[] height, int w)
    (be sure your method is public)
        
     

    Notes

    - Your return value must have a relative or an absolute error of less than 1e-9.

    Constraints

    - heights will contain between 1 and 50 elements, inclusive.
    - Each element of heights will be between 1 and 100, inclusive.
    - w will be between 1 and 100, inclusive.

    Examples

    0)  
        
    {3,3,3}
    2
    Returns: 5.656854249492381
     
    1)  
        
    {1,1,1,1}
    100
    Returns: 300.0
     
    2)  
        
    {100,2,100,2,100}
    4
    Returns: 396.32310051270036
    We will need the most rope if columns 0, 2, and 4 have height 100 each, and columns 1 and 3 have height 1 each.
    3)  
        
    {2,1,1,2}
    1
    Returns: 3.82842712474619

     这一题使用动态规划的方法。

    使用一个dp[i][j]数组,i 代表第i个位置,j代表i个位置上高度为j。

    for(i=1;i<N;i++){

    for(j=1;j<=H[i];j++){

    for(k=1;k<=H[i-1];k++){

    double dis=Math.sqrt((j-k)*(j-k)+w*w);

    if(dp[i][j]<dp[i-1][k]+dis){

    dp[i][j]=dp[i-1][k]+dis;

    }

    }

    }

    }

  • 相关阅读:
    Apache Kylin v3.0.0-alpha 发布
    Apache Kylin在美团点评的应用
    Kylin 架构模块简介
    Kylin 1 背景、历史与使命
    谈MongoDB的应用场景
    Linux 内存Cache和Buffer理解
    Linux 下查看内存使用情况方法总结
    mongodb 集群配置文件
    MongoDB bindIp 与 bindIpAll
    MongoDB 权限认证
  • 原文地址:https://www.cnblogs.com/gaoqichao/p/2591444.html
Copyright © 2020-2023  润新知