<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 97,  comments - 93,  trackbacks - 0
    Problem Statement

    A speed radar is installed in a highway zone where the maximum speed limit is maxLimit mph, and the minimum speed limit is minLimit mph. Any reading that is strictly above or below this interval is an infringement.
    Periodically, the radar readings are analyzed to make sure that the sensors are working properly. It is assumed that most drivers obey speed limits, and therefore, the radar will be considered faulty if more than 10% of its readings are infringements.
    Given the radar readings over a period of time, return the average speed of all cars that are driving within the speed limits. If the radar is faulty, return 0.0.
    Definition
    ????
    Class:
    SpeedRadar
    Method:
    averageSpeed
    Parameters:
    int, int, int[]
    Returns:
    double
    Method signature:
    double averageSpeed(int minLimit, int maxLimit, int[] readings)
    (be sure your method is public)


    Notes
    -
    The returned value must be accurate to within a relative or absolute value of 1E-9.
    Constraints
    -
    maxLimit will be between 1 and 200, inclusive.
    -
    minLimit will be between 1 and maxLimit, inclusive.
    -
    readings will contain between 1 and 50 elements, inclusive.
    -
    Each element of readings will be between 1 and 200, inclusive.
    Examples
    0)

    1
    50
    {45, 40, 50}
    Returns: 45.0
    With all drivers within the speed limits, the return value is just the average speed.
    1)

    1
    50
    {42,43,44,45,46,47,48,49,50,51}
    Returns: 46.0
    There is only one driver infringing the limit, and it represents 10% of the total readings. The average speed of the other readings is 46.0.
    2)

    1
    50
    {42,46,48,50,52}
    Returns: 0.0
    Only one reading is outside the given limits, but it represents 20% of the total number of readings. We therefore assume that the radar is not working and return 0.0.
    3)

    20
    60
    {25,45,45,43,24,9,51,55,60,34,61,23,40,40,47,49,33,23,47,54,54}
    Returns: 41.68421052631579

    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.
     1 /**
     2   * Author Nicky Qu
     3   * All Rights Reserved Oct 20th, 2007
     4 */
     5 import java.util.Formatter;
     6 
     7 public class SpeedRadar{
     8   private double averageReading = 0.0;
     9    public double averageSpeed(int minLimit,int maxLimit,int[] readings){
    10       int sum = 0;
    11       int countinF = 0;
    12       double rate =0.0;
    13       for(int i=0;i<readings.length;i++){
    14          if((readings[i]> minLimit-1)&&(readings[i]<maxLimit+1)){
    15          sum = sum +readings[i];
    16          }else{
    17            countinF+=1;
    18            rate = countinF*1.0/readings.length;
    19            if(rate>0.1){
    20               sum = 0;
    21               break;
    22             }
    23          }
    24       }
    25       averageReading = sum*1.0/(readings.length-countinF);
    26       Formatter f = new Formatter();
    27       return Double.parseDouble(f.format("%.15e", averageReading).toString());
    28    }
    29 }


    posted on 2007-10-20 13:25 wqwqwqwqwq 閱讀(1271) 評論(1)  編輯  收藏 所屬分類: Data Structure && Algorithm

    FeedBack:
    # re: TopCoder TCHS1
    2007-10-22 13:29 | 曲強 Nicky
    public class SpeedRadar {

    public double averageSpeed(int minLimit, int maxLimit, int[] readings) {
    int bad = 0;
    int sum = 0;
    for (int a : readings)
    if (a < minLimit || a > maxLimit)
    bad++;
    else
    sum += a;
    if(bad*10>readings.length)
    return 0.0;
    else
    return sum*1./(readings.length-bad);
    }
    }  回復  更多評論
      
    <2007年10月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910




    常用鏈接

    留言簿(10)

    隨筆分類(95)

    隨筆檔案(97)

    文章檔案(10)

    相冊

    J2ME技術網站

    java技術相關

    mess

    搜索

    •  

    最新評論

    閱讀排行榜

    校園夢網網絡電話,中國最優秀的網絡電話
    主站蜘蛛池模板: 成人免费午夜视频| 中国一级特黄高清免费的大片中国一级黄色片 | 四虎影视永久免费观看地址| 亚洲一区二区三区在线 | 亚洲另类自拍丝袜第1页| 99精品一区二区免费视频| 亚洲色欲久久久综合网东京热| 特级毛片爽www免费版| 免费一级毛片一级毛片aa| 成人婷婷网色偷偷亚洲男人的天堂| 毛片免费观看网站| 亚洲av无码专区在线电影| 日日夜夜精品免费视频| 黄人成a动漫片免费网站| 亚洲成人一区二区| 巨胸狂喷奶水视频www网站免费| 亚洲深深色噜噜狠狠爱网站| 成人性生交大片免费看好| 亚洲成人午夜在线| 国产精品永久免费10000| 亚洲夂夂婷婷色拍WW47| AV免费网址在线观看| 国产亚洲美女精品久久久久| 亚洲丰满熟女一区二区哦| 国产gav成人免费播放视频| 乱爱性全过程免费视频| 国产国拍亚洲精品mv在线观看| 亚洲乱妇老熟女爽到高潮的片| 国产精品无码素人福利免费| 永久免费无码日韩视频| 亚洲精品中文字幕无码蜜桃| 巨波霸乳在线永久免费视频| 亚洲中文字幕无码中文字在线| 成全在线观看免费观看大全| 亚洲精品**中文毛片| 成人超污免费网站在线看| 一边摸一边桶一边脱免费视频| 亚洲妇熟XXXX妇色黄 | 永久免费av无码网站大全| 一级一级一片免费高清| 久久水蜜桃亚洲av无码精品麻豆|