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

            Why so serious? --[NKU]schindlerlee

            2009年11月22日星期日.sgu154 sgu175

            2009年11月22日星期日.sgu154 sgu175

            sgu154:非常好的數論+二分題目
            You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.

            Input
            One number Q written in the input (0<=Q<=10^8).

            Output
            Write "No solution", if there is no such number N, and N otherwise.

            Sample test(s)
            Input
            2
            Output
            10

            首先要明白一件事x!末尾的0的個數至于2和5的個數有關,又因為2的個數已經多余5,所以階乘末尾
            0的個數完全等價于所有數中5的個數
            所以階乘末尾0的個數可以用如下函數計算
            int count(int x) //count the num of 0s in x!
            {
                int res = 0;
                while(x > 0) {
                    res += x / 5;
                    x /= 5;
                }
                return res;
            }
            然后題目要求末尾個數有n個0的x!中,x為多少
            因為哦count函數具有單調增加的性質,所以完全可以二分尋找符合條件的x
            trick 1.n == 0 ,時答案是1
            trick 2.二分出來的結果有可能應該輸出No Solution !(具體原因自己考慮一下)

            sgu175:經典
            Let phi(W) is the result of encoding for algorithm:
            1. If the length of W is 1 then phi(W) is W;
            2. Let coded word is W = w1w2...wN and K = N / 2 (rounded down);
            3. phi(W) = phi(wNwN-1...wK+1) + phi(wKwK-1...w1).
            For example, phi('Ok') = 'kO', phi('abcd') = 'cdab'.
            Your task is to find position of letter wq in encoded word phi(W).

            Input
            Given integers N, q (1 <= N <= 10^9; 1<= q <= N), where N is the length of word W.

            Output
            Write position of letter wq in encoded word phi(W).

            Input
            9 4

            Output
            8

            讀完題之后,直覺的想法就是遞歸模擬,復雜度也對,也沒問題,但是就是很容易錯,編碼困難.
            要跟據level的奇偶性,分別討論,有興趣可以嘗試一下,我沒成功......

            google 了以下發現了一個很好的想法,以下是我跟據那個想法寫的遞歸版本
            LL n, q;
            int bin(LL n, LL q)
            {
                if(n <= 1) return 1;
                LL k = n / 2;
                if (q > k) {
                    return bin(n - k, n - q + 1);
                } else {
                    return n - k + bin(k, k - q + 1);
                }
            }

            以如下為例,解釋以下算法
                 分裂  abcdefghi  時
                           /\                                                              
                          /  \                                                             
                       ihgfe dcba                                                          
               對于一個n,k = n / 2:
               如果 q <= k,這時abcd被倒置,如果要在dcba中找d,等價于在abcd中找a
                    也就是k到q的距離成為了新的q
               如果 q >  k,如果要在ihgfe中找h等價于在efghi中尋找f
                    也就是k到n的距離成為了新的q

            然后在體會一下上邊的算法                  
                                                                                           

            posted on 2009-11-23 00:24 schindlerlee 閱讀(1308) 評論(0)  編輯 收藏 引用 所屬分類: 解題報告

            久久99精品久久久久久久不卡| 国产香蕉97碰碰久久人人| 中文字幕日本人妻久久久免费 | 人妻无码αv中文字幕久久| 精品久久久久久无码中文字幕一区| 国产激情久久久久影院老熟女| 国产精品一区二区久久精品涩爱| 国产亚洲美女精品久久久久狼| 久久国内免费视频| 国产农村妇女毛片精品久久| 久久综合综合久久综合| 天天做夜夜做久久做狠狠| 久久99亚洲网美利坚合众国| 热久久最新网站获取| 日本精品久久久久中文字幕| 久久99国产乱子伦精品免费| 午夜精品久久久久久影视riav| 久久久精品久久久久特色影视| 精品国产乱码久久久久久郑州公司 | 久久无码人妻精品一区二区三区 | 精品人妻伦一二三区久久| 久久精品夜夜夜夜夜久久| 日本精品久久久久久久久免费| 狠狠色婷婷综合天天久久丁香| 亚洲精品乱码久久久久久蜜桃不卡 | 国产精品免费看久久久香蕉| 色88久久久久高潮综合影院| 欧美一区二区久久精品| 一个色综合久久| 亚洲精品无码久久久| 一本大道久久香蕉成人网| 久久综合色老色| 无码伊人66久久大杳蕉网站谷歌| 77777亚洲午夜久久多喷| 亚洲精品国精品久久99热一| 日韩人妻无码精品久久免费一| 色偷偷偷久久伊人大杳蕉| 久久精品水蜜桃av综合天堂 | 欧美久久亚洲精品| 亚洲欧洲精品成人久久奇米网| 久久WWW免费人成一看片|