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


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

            #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;
            ????????}
            ????}
            }

            //生成長度為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 閱讀(1319) 評論(2)  編輯 收藏 引用 所屬分類: AlgorithmUSACO

            評論

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

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

            # re: USACO 2.2 Runaround Numbers 2009-06-24 15:05 止于自娛

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

            導(dǎo)航

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

            統(tǒng)計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            国产精品99久久久久久人| 狠狠色婷婷综合天天久久丁香| 亚洲国产精品嫩草影院久久| 久久亚洲精品成人AV| 人妻无码精品久久亚瑟影视| 久久久久无码精品国产不卡| 久久久久久久免费视频| 精品无码久久久久国产| 国产精品18久久久久久vr| 2021少妇久久久久久久久久| 国产精品九九九久久九九| 91精品国产91久久久久久蜜臀| 久久精品这里热有精品| 亚洲国产精品久久| 久久人妻无码中文字幕| 久久99精品国产| 久久久久久久综合日本| 国产三级观看久久| 久久精品夜夜夜夜夜久久| 国产精品日韩深夜福利久久| 久久av高潮av无码av喷吹| 久久精品国产精品青草app| 久久久久免费精品国产| 狠狠色丁香婷婷久久综合五月| 久久婷婷五月综合97色一本一本| 94久久国产乱子伦精品免费| 99精品久久久久久久婷婷| 久久精品免费大片国产大片| 国产成年无码久久久免费| 欧美日韩精品久久久免费观看| 精品熟女少妇aⅴ免费久久| 国产激情久久久久影院老熟女免费 | 久久亚洲精品国产精品| 久久综合给合久久狠狠狠97色 | 久久久久成人精品无码| 亚洲中文字幕久久精品无码喷水| 9191精品国产免费久久 | 丁香久久婷婷国产午夜视频| 久久婷婷国产剧情内射白浆| 国内精品久久久久久久影视麻豆 | 久久国产精品免费一区二区三区|