• <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 2.2 Runaround Numbers


            生成所有長(zhǎng)度小于9的排列數(shù),然后判斷是否為runaround數(shù)且大于m,輸出第一個(gè)大于m的直接exit即可。
            因?yàn)?! = 362880,數(shù)據(jù)較小,不會(huì)超時(shí)。

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

            using?namespace?std;

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

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

            int?m;
            bool?mark[10];
            int?figures[10];


            void?solve();
            void?permutation(int?max_dep);
            unsigned?
            long?get_value(int?len);
            bool?isok(int?len);

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

            void?solve()
            {
            ????
            in>>m;

            ????
            int?start?=?0;
            ????
            int?tmp?=?m;
            ????
            while(tmp){
            ????????tmp
            /=10;
            ????????start
            ++;
            ????}

            ????
            for(int?i=start;i<=9;++i){
            ????????permutation(i);
            ????}
            }


            void?_permutation(int?depth,int?max_dep)
            {
            ????
            if(depth==max_dep){
            ??????
            if(isok(max_dep)){
            ?
            /*????????for(int?i=0;i<max_dep;++i)
            ????????????cout<<figures[i]<<'?';
            ????????cout<<endl;
            ??
            */???????unsigned?long?t?=?get_value(max_dep);

            ????????????
            if(t>m){
            ????????????????
            out<<t<<endl;
            ????????????????exit(
            0);
            ????????????}
            ????????}
            ????????
            return;
            ????}

            ????
            for(int?i=1;i<=9;++i){
            ????????
            if(!mark[i]){
            ????????????mark[i]?
            =?true;
            ????????????figures[depth]?
            =?i;
            ????????????_permutation(depth
            +1,max_dep);
            ????????????mark[i]?
            =?false;
            ????????}
            ????}
            }

            //生成長(zhǎng)度為len的全排列
            void?permutation(int?len)
            {
            ????memset(mark,
            0,sizeof(mark));
            ????_permutation(
            0,len);
            }

            //是runaround數(shù)
            bool?isok(int?len)
            {
            ????
            int?unvisited?=?len;
            ????
            bool?mark[10];
            ????memset(mark,
            0,sizeof(mark));

            ????
            int?i?=?0;
            ????
            while(unvisited--){
            ???????i
            +=figures[i];?i%=(len);
            ???????
            if(mark[i])?return?false;
            ???????mark[i]?
            =?true;
            ????}
            ????
            return?true;
            }

            //將數(shù)組轉(zhuǎn)化成unsigned?long
            unsigned?long?get_value(int?len)
            {
            ????unsigned?
            long?res?=?0;
            ????
            for(int?i=0;i<len;++i){
            ????????res
            *=10;
            ????????res
            +=figures[i];
            ????}

            ????
            return?res;
            }



            posted on 2009-06-20 22:35 YZY 閱讀(1309) 評(píng)論(2)  編輯 收藏 引用 所屬分類(lèi): AlgorithmUSACO

            評(píng)論

            # re: USACO 2.2 Runaround Numbers 2009-06-24 14:58 ChenZB

            呃...初學(xué)C++一年,宏定義還不太會(huì)用...基本沒(méi)用囧~~  回復(fù)  更多評(píng)論   

            # re: USACO 2.2 Runaround Numbers 2009-06-24 15:05 止于自?shī)?/a>

            @ChenZB
            我這宏沒(méi)啥用,方便調(diào)試而已.  
            回復(fù)  更多評(píng)論   

            導(dǎo)航

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

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類(lèi)

            隨筆檔案

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            国产亚洲综合久久系列| 久久久久亚洲AV成人片| 久久91综合国产91久久精品| 国产一级持黄大片99久久| 国内精品久久久久久麻豆| 四虎亚洲国产成人久久精品| 男女久久久国产一区二区三区| 久久精品国产91久久综合麻豆自制| 精品熟女少妇aⅴ免费久久| 国内精品九九久久精品 | 久久影院午夜理论片无码| 婷婷久久精品国产| 精品乱码久久久久久久| 久久人妻少妇嫩草AV无码蜜桃| 亚洲国产精品无码久久久秋霞2| 99久久精品国产免看国产一区| 三级片免费观看久久| 粉嫩小泬无遮挡久久久久久 | 99久久综合国产精品免费| 久久久久亚洲AV成人片| 亚洲欧美成人久久综合中文网| 久久影院综合精品| 久久亚洲AV无码精品色午夜| A狠狠久久蜜臀婷色中文网| 日产精品久久久久久久| AA级片免费看视频久久| 亚洲综合精品香蕉久久网| 久久久久国产一区二区| 久久国产精品-国产精品| 国产精品99久久久久久宅男小说| 99久久精品九九亚洲精品| 丁香狠狠色婷婷久久综合| 99久久99这里只有免费费精品| 久久久久久国产精品美女| 香蕉99久久国产综合精品宅男自| 国产精品午夜久久| 91精品国产高清久久久久久国产嫩草 | 精品免费久久久久国产一区| 日韩精品无码久久久久久| 99久久国产宗和精品1上映 | 国产精品久久久久久久|