• <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數(shù)直到第n個為止。
            對每一個prime,用二分法找出乘以已有的humble數(shù)且>=現(xiàn)有最大的humble數(shù)的最小的那一個。
            然后取最小的那一個作為新找到的humble數(shù)。
            開始的時候最后一個例子總是超時,后來用一個next_min數(shù)組緩存一下結(jié)果,效率一下提高了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

            導(dǎo)航

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

            統(tǒng)計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            亚洲精品乱码久久久久66| 久久se这里只有精品| 久久这里的只有是精品23| 青青青青久久精品国产h久久精品五福影院1421 | 2021少妇久久久久久久久久| 日本精品久久久久中文字幕| 久久中文字幕视频、最近更新| 超级97碰碰碰碰久久久久最新| 蜜臀久久99精品久久久久久小说| 久久国产成人精品麻豆| 一97日本道伊人久久综合影院| 潮喷大喷水系列无码久久精品| 欧美大战日韩91综合一区婷婷久久青草 | 久久91精品国产91久久麻豆| 国内精品久久久久国产盗摄| 久久久久无码精品国产不卡| 久久久中文字幕日本| 国产99久久精品一区二区| 伊人久久无码精品中文字幕| 国内精品久久久久久久久| 国产精品国色综合久久| 亚洲欧洲日产国码无码久久99 | 青春久久| 99久久精品免费| 精品久久一区二区三区| 久久永久免费人妻精品下载| 亚洲&#228;v永久无码精品天堂久久 | 亚洲精品无码专区久久久| 少妇熟女久久综合网色欲| 久久久WWW成人| 国产ww久久久久久久久久| 成人免费网站久久久| 久久精品亚洲日本波多野结衣| 久久久久久精品久久久久| 亚洲国产综合久久天堂| 久久99精品免费一区二区| 久久最新精品国产| 91精品国产91久久| 久久久久亚洲AV无码专区网站| 久久99精品久久久久久水蜜桃| 久久国产V一级毛多内射|