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

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

            #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 閱讀(646) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO動(dòng)態(tài)規(guī)劃

            導(dǎo)航

            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久精品国产99国产精偷| 伊人久久精品无码二区麻豆| 久久国产精品国产自线拍免费| 69久久夜色精品国产69| 精品久久人人妻人人做精品| 久久午夜免费视频| 久久99免费视频| 久久久久久久综合狠狠综合| 国内精品伊人久久久久| 久久国产免费| 精品国产91久久久久久久| 久久天天躁狠狠躁夜夜2020一| 99久久婷婷国产综合亚洲| 一日本道伊人久久综合影| 国产精品亚洲美女久久久| 久久久久久夜精品精品免费啦| 蜜桃麻豆www久久国产精品| 亚洲国产精品久久电影欧美| 久久亚洲国产精品五月天婷| 久久精品国产精品国产精品污| 久久久久99这里有精品10| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产精品美女久久久久久2018| 少妇久久久久久被弄到高潮| 99国内精品久久久久久久| 久久精品国产亚洲AV嫖农村妇女 | 久久成人小视频| 久久精品国产亚洲AV不卡| 久久美女网站免费| 久久久无码精品亚洲日韩按摩| 亚洲va中文字幕无码久久| 亚洲欧美国产日韩综合久久| 国产免费久久精品丫丫| 国产精品久久久99| 久久久久亚洲精品男人的天堂| 久久人人爽人人爽人人片AV麻豆| 久久99亚洲综合精品首页| 精品久久久久久久久久中文字幕| 日本道色综合久久影院| 国产精品成人精品久久久| 久久久国产一区二区三区|