emu in blogjava

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            171 隨筆 :: 103 文章 :: 1052 評論 :: 2 Trackbacks
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          公告

          常用鏈接

          留言簿(92)

          隨筆分類(20)

          隨筆檔案(171)

          文章分類(89)

          文章檔案(103)

          相冊

          收藏夾(46)

          友情連接

          收藏

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          Problem Statement
          ????
          With all the different cell phone plans being offered these days, it is often difficult to pick the one that provides the best values for a particular usage pattern. In this problem, we will consider cell phone plans that provide a fixed number of minutes each month for a certain fee. If you go over the fixed number of minutes, you must pay an additional fee per minute. Additionally, some plans offer free off hour (night and weekend) calls, while other plans treat off hour calls the same as peak hour calls. If a plan offers free off hour calling, then the calls made during off hours don't use up the fixed number of minutes you get each month.  You will be given a String[], plans, each element of which represents a cell phone plan. Each plan will be formatted as "<PRICE> <MINUTES> <COST PER MINUTE> <OFF>" (quotes and angle brackets for clarity only). <PRICE> will be an integer representing the number of cents per month that one must pay for the plan. <MINUTES> will represent the number of free minutes the plan provides, per month. <COST PER MINUTE> will represent the price in cents of each additional minute in a month, beyond the first <MINUTES>. <OFF> will be either 'T' or 'F', representing whether off hour calls are free ('T') or not ('F'). Additionally, you will be given two int[]s. peakMinutes will represent the number of minutes spent talking during peak hours, while offMinutes will represent the number of minutes spent talking during off hours. Corresponding elements of peakMinutes and offMinutes will represent a single month of use.  Your task is to return the index (starting from 0) of the cheapest plan over all the months given as input. If there is a tie, return the lowest index among tied plans.
          Definition
          ????
          Class:
          CellPlans
          Method:
          cheapest
          Parameters:
          String[], int[], int[]
          Returns:
          int
          Method signature:
          int cheapest(String[] plans, int[] peakMinutes, int[] offMinutes)
          (be sure your method is public)
          ????

          Constraints
          -
          plans will contain between 1 and 50 elements, inclusive.
          -
          Each element of plans will be formatted as "<PRICE> <MINUTES> <COST PER MINUTE> <OFF>".
          -
          <PRICE> will be between 0 and 100000, inclusive, with no extraneous leading zeros.
          -
          <MINUTES> will be between 0 and 50000, inclusive, with no extraneous leading zeros.
          -
          <COST PER MINUTE> will be between 0 and 1000, inclusive, with no extraneous leading zeros.
          -
          <OFF> will be either 'T' or 'F'.
          -
          peakMinutes will contain between 1 and 50 elements, inclusive.
          -
          offMinutes will contain the same number of elements as peakMinutes.
          -
          Each element of offMinutes and peakMinutes will be between 0 and 25000, inclusive.
          Examples
          0)

          ????
          {"2999 1000 29 T",
           "5999 3000 49 F",
           "999 0 19 F"}
          {1543,463,754,405,0,30}
          {100,2053,1003,534,2595,3056}
          Returns: 0
          Plan 0 provides 1000 free minutes, and free off hour calling. For the 6 months given, we must pay the base rate (2999) each month for a total of 17994. Additionally, we used an extra 543 minutes during the first month, for which we must pay 543*29 = 15747. 15747 + 17994 = 33741.  Plan 1 would end up costing 40208, while plan 2 would end up costing 244178.
          1)

          ????
          {"10000 0 0 T","10000 0 0 F"}
          {20000,25000}
          {25000,20000}
          Returns: 0
          These plans always cost the same amount since it doesn't matter whether you get free off hour calling when the calls are already free. Since there is a tie, return the lower index.
          2)

          ????
          {"100000 0 1000 F","100000 0 10 F"}
          {25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000}
          {25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
           25000,25000,25000,25000,25000,25000}
          Returns: 1
          Beware of overflow.
          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.

           

          posted on 2005-08-16 09:29 emu 閱讀(1234) 評論(1)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

          評論

          # emu的解法 2005-08-16 10:01 emu
          送分題。主要難度是在理解題目的描述上。

          public class CellPlans
          {
          public static void main(String[] args)
          {
          String [] plans = new String []{"2999 1000 29 T","5999 3000 49 F","999 0 19 F"};
          int[] peakMinutes = new int[]{1543,463,754,405,0,30};
          int[] offMinutes = new int[]{100,2053,1003,534,2595,3056};
          int cheapest = new CellPlans().cheapest(plans,peakMinutes,offMinutes);
          System.out.println("cheapest plan is :"+cheapest);

          plans = new String []{"10000 0 0 T","10000 0 0 F"};
          peakMinutes = new int[]{20000,25000};
          offMinutes = new int[]{25000,20000};
          cheapest = new CellPlans().cheapest(plans,peakMinutes,offMinutes);
          System.out.println("cheapest plan is :"+cheapest);

          plans = new String []{"100000 0 1000 F","100000 0 10 F"};
          peakMinutes = new int[]{25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000};
          offMinutes = new int[]{25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,25000,
          25000,25000,25000,25000,25000,25000};
          cheapest = new CellPlans().cheapest(plans,peakMinutes,offMinutes);
          System.out.println("cheapest plan is :"+cheapest);

          }

          public int cheapest(String[] plans, int[] peakMinutes, int[] offMinutes){
          double min = count(plans[0],peakMinutes,offMinutes);
          int result = 0;
          for (int i=1;i<plans.length;i++){
          double c = count(plans[ i ],peakMinutes,offMinutes);
          if (c<min){
          min=c;
          result = i;
          }
          }
          return result;
          }
          private double count(String plan,int[] peakMinutes,int[] offMinutes){
          String[] ar = plan.split(" ");
          double price = Float.parseFloat(ar[0]);
          int minutes = Integer.parseInt(ar[1],10);
          double costPerMin = Float.parseFloat(ar[2]);
          boolean offHours = "T".equals(ar[3]);
          double result = peakMinutes.length*price;
          for(int i=0;i<peakMinutes.length;i++){
          if (offHours){
          result += costPerMin*((peakMinutes[ i ]>minutes?(peakMinutes[ i ]-minutes):0));
          }else{
          result += costPerMin*((peakMinutes[ i ]+offMinutes[ i ])>minutes?(peakMinutes[ i ]+offMinutes[ i ]-minutes):0);
          }
          }
          return result;
          }

          }
            回復(fù)  更多評論
            

          主站蜘蛛池模板: 宜宾市| 富阳市| 望都县| 道孚县| 防城港市| 祁门县| 岑溪市| 大埔县| 忻州市| 旌德县| 博白县| 晋宁县| 新乐市| 扬州市| 聊城市| 宜城市| 湖北省| 永春县| 南京市| 镇宁| 威信县| 夏津县| 邮箱| 久治县| 封开县| 卢龙县| 静宁县| 隆回县| 鄂尔多斯市| 凤凰县| 文化| 扶沟县| 宾川县| 商都县| 马山县| 朝阳县| 瑞金市| 桑植县| 武威市| 札达县| 嘉黎县|