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

            USACO 4.1 Beef McNuggets

            這題有些難。雖然知道是動態規劃題,但是不知道要開多大的數組,后來看analysis用一個256大小的數組循環使用,方法很巧妙。
            先將box進行排序。
            如果box里面的數的最大公約數不為1的話,那么所有組成的數,只可能是這個公約數的倍數,因此沒有上限,輸出為0.
            用last記錄最小的“不能組成的數”。這樣當last之后有boxs[0]個連續數都可以組成的話,那么所有的數都可以組成。
            last+1...last+box[0]可以組成的話,那么每個數都加一個box[0],那么新一輪的box[0]個數也可以組成,以此類推。

            #include?<iostream>
            #include?
            <fstream>

            using?namespace?std;

            ifstream?fin(
            "nuggets.in");
            ofstream?fout(
            "nuggets.out");

            #ifdef?_DEBUG
            #define?out?cout
            #define?in?cin
            #else
            #define?out?fout
            #define?in?fin
            #endif

            int?box_num;
            int?boxs[10];

            bool?ok[256];

            int?gcd(int?a,int?b)
            {
            ????
            if(a<b)?swap(a,b);

            ????
            int?tmp;

            ????
            while(b!=0){
            ????????tmp?
            =?a;
            ????????a?
            =?b;
            ????????b?
            =?tmp%b;
            ????}

            ????
            return?a;
            }

            void?solve()
            {

            ????
            in>>box_num;
            ????
            for(int?i=0;i<box_num;++i)
            ????????
            in>>boxs[i];

            ????sort(
            &boxs[0],&boxs[box_num]);
            ????
            ????
            int?t?=?boxs[0];

            ????
            for(int?i=1;i<box_num;++i){
            ????????t?
            =?gcd(t,boxs[i]);
            ????}

            ????
            if(t!=1){
            ????????
            out<<0<<endl;
            ????????
            return;
            ????}

            ????memset(ok,
            0,sizeof(ok));

            ????
            int?last?=?0;
            ????ok[
            0]?=?true;
            ????
            int?i=0;

            ????
            while(true){
            ????????
            if(ok[i%256]){
            ????????????ok[i
            %256]?=?0;
            ????????????
            if(i-last>=boxs[0]){
            ????????????????
            out<<last<<endl;
            ????????????????
            return;
            ????????????}
            ????????????
            for(int?x=0;x<box_num;++x){
            ????????????????ok[(i
            +boxs[x])%256]?=?true;
            ????????????}
            ????????}
            else{
            ????????????last?
            =?i;
            ????????}
            ????????
            ++i;
            ????}
            }

            int?main(int?argc,char?*argv[])
            {
            ????solve();?
            ????
            return?0;
            }


            Beef McNuggets

            Hubert Chen

            Farmer Brown's cows are up in arms, having heard that McDonalds is considering the introduction of a new product: Beef McNuggets. The cows are trying to find any possible way to put such a product in a negative light.

            One strategy the cows are pursuing is that of `inferior packaging'. ``Look,'' say the cows, ``if you have Beef McNuggets in boxes of 3, 6, and 10, you can not satisfy a customer who wants 1, 2, 4, 5, 7, 8, 11, 14, or 17 McNuggets. Bad packaging: bad product.''

            Help the cows. Given N (the number of packaging options, 1 <= N <= 10), and a set of N positive integers (1 <= i <= 256) that represent the number of nuggets in the various packages, output the largest number of nuggets that can not be purchased by buying nuggets in the given sizes. Print 0 if all possible purchases can be made or if there is no bound to the largest number.

            The largest impossible number (if it exists) will be no larger than 2,000,000,000.

            PROGRAM NAME: nuggets

            INPUT FORMAT

            Line 1: N, the number of packaging options
            Line 2..N+1: The number of nuggets in one kind of box

            SAMPLE INPUT (file nuggets.in)

            3
            3
            6
            10

            OUTPUT FORMAT

            The output file should contain a single line containing a single integer that represents the largest number of nuggets that can not be represented or 0 if all possible purchases can be made or if there is no bound to the largest number.

            SAMPLE OUTPUT (file nuggets.out)

            17

            posted on 2009-07-12 14:58 YZY 閱讀(639) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm 、USACO動態規劃

            導航

            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            中文成人无码精品久久久不卡| 国产精品久久亚洲不卡动漫| 久久综合色区| 久久精品国产日本波多野结衣| 久久久久久久久波多野高潮| MM131亚洲国产美女久久| 国产精品va久久久久久久| 亚洲一级Av无码毛片久久精品| 久久99国内精品自在现线| 久久国产香蕉视频| 久久久久成人精品无码中文字幕 | 热re99久久精品国99热| 99久久精品免费看国产免费| 国产精品久久新婚兰兰| 九九久久99综合一区二区| 伊人久久大香线蕉综合5g| 99久久精品免费看国产一区二区三区| 久久久久亚洲精品日久生情 | 久久被窝电影亚洲爽爽爽| 欧美国产成人久久精品| 久久国产视屏| 国产无套内射久久久国产| a高清免费毛片久久| 无码超乳爆乳中文字幕久久| 日韩va亚洲va欧美va久久| 狠狠精品久久久无码中文字幕| 人妻精品久久无码区| 久久久噜噜噜久久中文字幕色伊伊 | 亚洲国产成人精品女人久久久| 午夜不卡888久久| 久久国产精品一区二区| 国产精品久久久久久久久鸭| 久久久一本精品99久久精品88| 久久精品国产99久久久古代| 日本精品一区二区久久久| 久久久久无码中| 欧美亚洲国产精品久久| 性做久久久久久久久老女人| 亚洲国产精品一区二区三区久久| 久久97久久97精品免视看| 久久久久亚洲av毛片大|