• <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 3.1 Humble Numbers



            每次找下一個最小的humble數直到第n個為止。
            對每一個prime,用二分法找出乘以已有的humble數且>=現有最大的humble數的最小的那一個。
            然后取最小的那一個作為新找到的humble數。
            開始的時候最后一個例子總是超時,后來用一個next_min數組緩存一下結果,效率一下提高了10倍。

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

            using?namespace?std;

            int?humbles[100002];
            int?primes[100];
            int?k,n;
            int?top;

            int?next_min[100];

            long?long?find_next(int?i)
            {
            ????
            int?l?=?0;
            ????
            int?h?=?top;
            ????
            int?mid;

            ????
            while(l<=h){
            ????????mid?
            =?(l+h)/2;
            ????????
            if((long?long)humbles[mid]*primes[i]<=humbles[top]){
            ????????????l?
            =?mid+1;
            ????????}
            else{
            ????????????h?
            =?mid-1;
            ????????}
            ????}

            ????
            return?humbles[h+1]*primes[i];
            }

            void?solve()
            {
            ????humbles[
            0]?=?1;
            ????top?
            =?0;

            ????freopen(
            "humble.in","r",stdin);
            ????freopen(
            "humble.out","w",stdout);

            ????scanf(
            "%d%d",&k,&n);

            ????
            for(int?i=0;i<k;++i)
            ????????scanf(
            "%d",&primes[i]);

            ????
            for(int?i=0;i<k;++i)
            ????????next_min[i]?
            =?find_next(i);

            ????
            while(top<n){
            ????????
            long?long?next?=?LONG_MAX;
            ????????
            long?long?tmp;
            ????????
            for(int?i=0;i<k;++i){
            ????????????
            if(next_min[i]<=humbles[top])
            ????????????????tmp?
            =?next_min[i]?=?find_next(i);
            ????????????
            else
            ????????????????tmp?
            =?next_min[i];

            ????????????
            if(tmp<next){
            ????????????????next?
            =?tmp;
            ????????????}
            ????????????
            if(next==humbles[top]+1)
            ????????????????
            break;
            ????????}
            ????????humbles[
            ++top]?=?next;
            ????}

            ????printf(
            "%d\n",humbles[n]);
            }

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

            posted on 2009-06-30 00:05 YZY 閱讀(1674) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO

            導航

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            欧美午夜A∨大片久久 | 合区精品久久久中文字幕一区| 精品欧美一区二区三区久久久| 久久国产成人亚洲精品影院| 人妻丰满?V无码久久不卡| 18岁日韩内射颜射午夜久久成人 | 国产99精品久久| 久久久久国产一级毛片高清板| 久久精品亚洲AV久久久无码| 狠狠干狠狠久久| 久久午夜福利无码1000合集| 国产精品视频久久久| 久久久久成人精品无码| 国产精品99久久免费观看| 久久人人爽人人爽人人片av麻烦 | 97久久香蕉国产线看观看| 人妻中文久久久久| 欧美久久精品一级c片片| 亚洲va国产va天堂va久久| 日本久久中文字幕| 9191精品国产免费久久| 久久久噜噜噜久久熟女AA片| 亚洲精品国精品久久99热| 久久久99精品一区二区| 精品国产福利久久久| 久久亚洲AV成人无码电影| 久久综合久久综合亚洲| 久久精品一区二区三区中文字幕| 午夜精品久久久久久久| 久久久久久久波多野结衣高潮| 久久国产三级无码一区二区| 久久99国产精品久久| 99久久精品国产免看国产一区| 亚洲AV日韩精品久久久久| 中文字幕久久精品无码| 久久精品国产日本波多野结衣| 亚洲欧美国产日韩综合久久| 久久久久99精品成人片三人毛片| 精品国产热久久久福利| 亚洲国产综合久久天堂| 久久久久人妻一区二区三区|