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

            pku1920 Towers of Hanoi 河內塔問題

            給出河內塔的中間狀態,求將所有盤子摞到一起的的最小步數。
            先貼程序
             1 import java.util.*;
             2 import java.io.*;
             3 public class Main {
             4 
             5     /**
             6      * @param args
             7      */
             8     static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
             9     static final int nextInt() throws Exception
            10     {
            11         in.nextToken();
            12         return (int)in.nval;
            13     }
            14     public static void main(String[] args) throws Exception{
            15         
            16         int num=nextInt();
            17         int step[]=new int[num+1];
            18         int id[]=new int[num+1];
            19         step[1]=1;
            20         for(int i=2;i<=num;i++)
            21             step[i]= (step[i-1]<<1)%1000000;
            22         ArrayList<Integer> data[]=new ArrayList[3];
            23         for(int i=0;i<3;i++)
            24             data[i]=new ArrayList<Integer>();
            25         int a=nextInt(),b=nextInt(),c=nextInt();
            26         while((a--)!=0)
            27             id[nextInt()]=0;
            28         while((b--)!=0)
            29             id[nextInt()]=1;
            30         while((c--)!=0)
            31             id[nextInt()]=2;
            32         int s=id[num],e=s,mid=0,total=0;
            33         for(int i=num;i>=1;)
            34         {
            35             if(s!=e)
            36             {
            37                 total=(step[i]+total)%1000000;
            38                 e=mid;
            39             }
            40             s=id[--i];
            41             mid=3-s-e;
            42         }
            43         System.out.println(id[num]+1);
            44         System.out.println(total);
            45         
            46         
            47         
            48     }
            49 
            50 }
            51 


            posted on 2010-11-01 02:31 yzhw 閱讀(213) 評論(0)  編輯 收藏 引用 所屬分類: combination math 、data struct

            <2010年12月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久99热只有频精品8| 久久久久久久97| 亚洲а∨天堂久久精品9966| 午夜福利91久久福利| 青草国产精品久久久久久| 久久国产成人午夜aⅴ影院| 日本WV一本一道久久香蕉| 国产精品久久亚洲不卡动漫| 99久久免费国产精品特黄| 91视频国产91久久久| 女同久久| 精品国产青草久久久久福利| 国产精品免费看久久久| 久久精品成人| 国产精品久久久久久久午夜片 | 久久亚洲中文字幕精品有坂深雪| 久久97久久97精品免视看| 欧洲人妻丰满av无码久久不卡| 久久免费观看视频| 91精品免费久久久久久久久| 精品久久久久久国产潘金莲| 无码精品久久久久久人妻中字| 久久久久无码中| 久久成人永久免费播放| 国产精品伊人久久伊人电影 | 亚洲精品乱码久久久久久| 丰满少妇人妻久久久久久4| 国内精品久久久久影院优| 天天躁日日躁狠狠久久| 中文字幕无码精品亚洲资源网久久| 久久久青草青青国产亚洲免观| 国产精品免费久久久久电影网| 嫩草影院久久99| 国产农村妇女毛片精品久久| 国产成人精品久久一区二区三区av | 69久久夜色精品国产69| 狠狠干狠狠久久| 精品国产一区二区三区久久蜜臀| 91久久精品国产成人久久| 手机看片久久高清国产日韩| 久久91精品国产91|