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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            題目地址:
            http://acm.hdu.edu.cn/showproblem.php?pid=1016
            題目描述:

            Prime Ring Problem

            Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
            Total Submission(s): 6150    Accepted Submission(s): 2745


            Problem Description
            A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.

            Note: the number of first circle should always be 1.


            Input
            n (0 < n < 20).

            Output
            The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements. Print solutions in lexicographical order.

            You are to write a program that completes above process.

            Print a blank line after each case.

            Sample Input
            6 8

            Sample Output
            Case 1: 1 4 3 2 5 6 1 6 5 2 3 4 Case 2: 1 2 3 8 5 6 7 4 1 2 5 8 3 4 7 6 1 4 7 6 5 8 3 2 1 6 7 4 3 8 5 2
            題目分析:
            典型的 DFS 題目, 不需要 什么剪枝, 直接 窮舉 + 回溯 就OK了, 不過值得一提的是,這題輸出很BT, 一般的 前后 輸出 回車 , 第一個回車用 if( n == 1 ) 回車; 來做PE了好幾次, 最后直接在程序最后 輸出2個回車符竟然就A了, YM啊...........
            代碼如下:
            /* MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋 http://www.shnenglu.com/MiYu Author By : MiYu Test : Program : */ #include <iostream> using namespace std; bool prim[25]; int res[25]; bool hash[25]; int N; void setPrim () { memset ( prim, 0, sizeof ( prim ) ); prim[2] = prim[3] = prim[5] = prim[7] = prim[11] = prim[13] = prim[17] = prim[19] = prim[23] = true; } bool DFS ( int num , int n ) { res[n] = num; if ( n > N ) { return false; } if ( n == N - 1 ) { for ( int i = 2; i <= N; ++ i ) { if ( prim[num + i] && prim[ i + 1 ] && !hash[i] ) { res[n+1] = i; for ( int i = 1; i <= N; ++ i ) printf ( i == 1 ? "%d" : " %d",res[i] ); putchar ( '\n' ); } } } for ( int i = 2; i <= N; ++ i ) { if ( prim[ num + i ] && !hash[i] ) { hash[i] = true; DFS ( i, n + 1 ); hash[i] = false; } } return false; } int main () { setPrim (); int ca = 1; while ( cin >> N ) { sizeof ( hash, 0 , sizeof ( hash ) ); printf ( "Case %d:\n",ca++ ); hash[1] = true; DFS ( 1, 1 ); putchar ( '\n' ); } return 0; }

            久久久久免费精品国产| 国产亚洲美女精品久久久2020| 久久午夜无码鲁丝片午夜精品| 精品久久久久久综合日本| 日本精品久久久中文字幕| 麻豆精品久久精品色综合| Xx性欧美肥妇精品久久久久久| 中文字幕成人精品久久不卡| 亚洲精品国精品久久99热一| 久久久久久国产a免费观看黄色大片 | 亚洲午夜久久久久久久久电影网| 婷婷久久综合九色综合98| 久久精品无码一区二区三区日韩| 久久精品国产一区二区电影| 久久国产午夜精品一区二区三区| 久久久久久免费视频| AAA级久久久精品无码片| 97精品伊人久久久大香线蕉| 国产高清美女一级a毛片久久w | 色综合久久88色综合天天| 久久天天躁狠狠躁夜夜2020老熟妇 | 99久久精品免费看国产一区二区三区| 久久精品嫩草影院| 久久夜色精品国产噜噜麻豆| 99国产欧美久久久精品蜜芽| 久久国产精品久久国产精品| 丰满少妇人妻久久久久久4| 亚洲国产视频久久| 久久免费观看视频| 久久精品国产一区二区三区| 久久久国产打桩机| 中文字幕无码久久精品青草| 韩国免费A级毛片久久| 亚洲伊人久久成综合人影院 | 亚洲欧洲久久av| 一本久久a久久精品综合香蕉 | 久久综合噜噜激激的五月天| 日本免费一区二区久久人人澡| A级毛片无码久久精品免费| 欧美粉嫩小泬久久久久久久 | 亚洲欧美日韩精品久久亚洲区 |