• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ArcTan

            dfs
            隨筆 - 16, 文章 - 117, 評論 - 6, 引用 - 0
            數據加載中……

            SRM 150 DIV 2 250pt(隊列)

            Problem Statement

                

            When a widget breaks, it is sent to the widget repair shop, which is capable of repairing at most numPerDay widgets per day. Given a record of the number of widgets that arrive at the shop each morning, your task is to determine how many days the shop must operate to repair all the widgets, not counting any days the shop spends entirely idle.

            For example, suppose the shop is capable of repairing at most 8 widgets per day, and over a stretch of 5 days, it receives 10, 0, 0, 4, and 20 widgets, respectively. The shop would operate on days 1 and 2, sit idle on day 3, and operate again on days 4 through 7. In total, the shop would operate for 6 days to repair all the widgets.

            Create a class WidgetRepairs containing a method days that takes a sequence of arrival counts arrivals (of type vector <int>) and an int numPerDay, and calculates the number of days of operation.

            Definition

                
            Class: WidgetRepairs
            Method: days
            Parameters: vector <int>, int
            Returns: int
            Method signature: int days(vector <int> arrivals, int numPerDay)
            (be sure your method is public)
                

            Constraints

            - arrivals contains between 1 and 20 elements, inclusive.
            - Each element of arrivals is between 0 and 100, inclusive.
            - numPerDay is between 1 and 50, inclusive.

            Examples

            0)
                
            { 10, 0, 0, 4, 20 }
            8
            Returns: 6
            The example above.
            1)
                
            { 0, 0, 0 }
            10
            Returns: 0

            2)
                
            { 100, 100 }
            10
            Returns: 20

            3)
                
            { 27, 0, 0, 0, 0, 9 }
            9
            Returns: 4

            4)
                
            { 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6 }
            3
            Returns: 15

            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.



            直接遍歷就行,每天完成不了的留到第二天做。最后沒有完成的延遲到后面做。
            求的的做的天數是多少,沒有做的那天不用算。

            228PT,速度還是慢了點。
            #include<stdio.h>
            #include
            <algorithm>
            #include
            <string.h>
            #include
            <vector>
            using namespace std;

            class WidgetRepairs{
            public:
                
            int days(vector <int> arrivals, int numPerDay){
                    
            int n=arrivals.size();
                    
            int now=0;
                    
            int i=0;
                    
            int tot=0;
                    
            while (i<|| now)  //這里可以優化一下,如果i==n就不用循環了,剩下的需要完成的天數為(now-1)/numPerDay+1。
                    {
                        
            if (i<n)
                            now
            +=arrivals[i];
                        
            if (now>0)   //第一次這里理解錯了,以后要把細節搞清楚啊。。。
                            tot++;
                        now
            =now>numPerDay?now-numPerDay:0;    
                        i
            ++;
                    }
                    
            return tot;
                }
            };







            posted on 2012-07-15 21:37 wangs 閱讀(228) 評論(0)  編輯 收藏 引用 所屬分類: Topcoder

            久久99精品免费一区二区| 国产精品99精品久久免费| 国产精品99久久免费观看| 精品午夜久久福利大片| 国产欧美一区二区久久| 日韩欧美亚洲综合久久影院d3| 亚洲国产精品一区二区久久| 51久久夜色精品国产| 久久伊人精品青青草原日本| 亚洲午夜久久久影院伊人| 国内精品伊人久久久久AV影院| 国产精品内射久久久久欢欢| 欧美亚洲国产精品久久久久| 五月丁香综合激情六月久久| 久久精品成人影院| 色婷婷综合久久久久中文一区二区| 国产精品福利一区二区久久| 亚洲精品国产自在久久| 热re99久久精品国产99热| 久久亚洲中文字幕精品一区| 国产AV影片久久久久久| 色婷婷综合久久久久中文| 久久久不卡国产精品一区二区| 色偷偷偷久久伊人大杳蕉| 久久亚洲中文字幕精品一区四| 国内精品伊人久久久久| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 青草久久久国产线免观| 99久久精品午夜一区二区| 久久亚洲精品无码aⅴ大香| 99久久综合国产精品二区| 精品综合久久久久久888蜜芽| 久久久www免费人成精品| 精品水蜜桃久久久久久久| 久久香蕉综合色一综合色88| 久久国产亚洲精品无码| 久久精品中文字幕无码绿巨人| 日本强好片久久久久久AAA| A级毛片无码久久精品免费| 97精品依人久久久大香线蕉97| 久久亚洲AV成人无码软件|