• <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>

            poj3273

            Monthly Expense

            Time Limit: 2000MS Memory Limit: 65536K
            Total Submissions: 8261 Accepted: 3399

            Description

            Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.

            FJ wants to create a budget for a sequential set of exactly M (1 ≤ MN) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.

            FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.

            Input

            Line 1: Two space-separated integers: N and M
            Lines 2..N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day

            Output

            Line 1: The smallest possible monthly limit Farmer John can afford to live with.

            Sample Input

            7 5
            100
            400
            300
            100
            500
            101
            400

            Sample Output

            500

            Hint

            If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. Any other method of scheduling gives a larger minimum monthly limit.


            題意很簡單,算法也很簡單,以前這種題目絕對做不出來,可能沒做過這種類型的吧
            現(xiàn)在看貌似很簡單,
            做法就是二分枚舉答案+貪心驗(yàn)證
            二分的下界取最大的數(shù)
            上界取所有數(shù)的和即可
            唔,昨晚上剛看到這題的時(shí)候,想著dp應(yīng)該是可以的
            不過測試數(shù)據(jù)是10w,又不行了,然后想著可以轉(zhuǎn)化成圖論的模型,不過點(diǎn)太多,還是不行
            然后搜索,dp都不行了,搜索也白搭,然后想二分,然后算了下只有10^9 ,頂多30多次 ,貌似可以
            …………

            #include<stdio.h>
            #include
            <string.h>
            #include
            <math.h>
            #define maxn 100005
            int n,m,a[maxn];
            int lower,upper;
            int max(int a,int b)
            {
                
            return a>b?a:b;
            }

            bool yanz(int x)
            {
                
            int num,i,tmp;
                num
            =0;
                i
            =1;
                
            while(i<=n)
                
            {
                    tmp
            =0;
                    
            while(tmp+a[i]<=x&&i<=n)
                    
            {
                        tmp
            =tmp+a[i];
                        i
            ++;
                    }

                    num
            ++;
                }

                
            if(num>m) return 0;
                
            return 1;
            }

            int main()
            {
                
            int i;
                
            while(scanf("%d%d",&n,&m)!=EOF)
                
            {
                    lower
            =-1;
                    upper
            =0;
                    
            for(i=1; i<=n; i++)
                    
            {
                        scanf(
            "%d",&a[i]);
                        lower
            =max(a[i],lower);
                        upper
            =upper+a[i];
                    }

                    
            //printf("%d %d\n",upper,lower);
                    int left,right;
                    left
            =lower;
                    right
            =upper;
                    
            while(left<right)
                    
            {
                        
            int mid=(left+right)/2;
                        
            if(yanz(mid)) right=mid; //printf("%d ok\n",right);}
                        else left=mid+1;
                    }

                    printf(
            "%d\n",left);
                }

                
            return 0;
            }


            wa了兩遍,發(fā)現(xiàn)最開始的時(shí)候tmp沒初始化

            posted on 2012-05-22 16:31 jh818012 閱讀(216) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
            • --王私江
            亚洲а∨天堂久久精品| 1000部精品久久久久久久久| 久久精品国产亚洲Aⅴ蜜臀色欲| 狠狠人妻久久久久久综合蜜桃| 青青久久精品国产免费看| 亚洲AV无码久久| 免费国产99久久久香蕉| 久久久久亚洲AV无码观看 | 久久久久久夜精品精品免费啦| 国产99精品久久| 欧美亚洲国产精品久久高清| 国产欧美久久久精品| 一本大道久久香蕉成人网| 激情伊人五月天久久综合| 久久夜色精品国产噜噜亚洲a | 国产精品热久久无码av| 日韩av无码久久精品免费| 久久久久久av无码免费看大片| 国产成人精品久久免费动漫 | 97久久久久人妻精品专区| 色青青草原桃花久久综合| 精品久久人人爽天天玩人人妻| 久久精品中文闷骚内射| 久久精品国产精品亚洲精品| 久久AAAA片一区二区| 久久最新精品国产| 久久91精品国产91久久小草| 久久夜色精品国产噜噜亚洲AV| 欧美伊人久久大香线蕉综合| 久久婷婷午色综合夜啪| 久久久噜噜噜久久中文字幕色伊伊| 91精品国产高清久久久久久国产嫩草 | 久久香蕉国产线看观看乱码| 久久精品亚洲日本波多野结衣| 国产亚洲精品久久久久秋霞| 日日狠狠久久偷偷色综合免费| 久久精品不卡| 青青草原综合久久大伊人| 精品久久久中文字幕人妻| 久久久久青草线蕉综合超碰| 亚洲va中文字幕无码久久|