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

            pku1309 數(shù)學(xué)優(yōu)化+枚舉

            題目
            Coconuts, Revisited
            Time Limit: 1000MS
            Memory Limit: 10000K
            Total Submissions: 1832
            Accepted: 737

            Description

            The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening Post on October 9, 1926. The story tells about five men and a monkey who were shipwrecked on an island. They spent the first night gathering coconuts. During the night, one man woke up and decided to take his share of the coconuts. He divided them into five piles. One coconut was left over so he gave it to the monkey, then hid his share and went back to sheep.

            Soon a second man woke up and did the same thing. After dividing the coconuts into five piles, one coconut was left over which he gave to the monkey. He then hid his share and went back to bed. The third, fourth, and fifth man followed exactly the same procedure. The next morning, after they all woke up, they divided the remaining coconuts into five equal shares. This time no coconuts were left over.

            An obvious question is "how many coconuts did they originally gather?" There are an infinite number of answers, but the lowest of these is 3,121. But that's not our problem here.

            Suppose we turn the problem around. If we know the number of coconuts that were gathered, what is the maximum number of persons (and one monkey) that could have been shipwrecked if the same procedure could occur?

            Input

            The input will consist of a sequence of integers, each representing the number of coconuts gathered by a group of persons (and a monkey) that were shipwrecked. The sequence will be followed by a negative number.

            Output

            For each number of coconuts, determine the largest number of persons who could have participated in the procedure described above. Display the results similar to the manner shown below, in the Expected Output. There may be no solution for some of the input cases; if so, state that observation.

            Sample Input

            25 30 3121 -1

            Sample Output

            25 coconuts, 3 people and 1 monkey 30 coconuts, no solution 3121 coconuts, 5 people and 1 monkey

            Source


            解法:
            首先寫出遞推公式
            f(0)=A  A=nk
            f(i)=f(i-1)/(n-1)*n+1

            隨便什么方法寫出閉形式
            f(n)=[(n^n)*(A+n-1)]/[(n-1)^n]-(n-1)
            題目中告訴f(n)的值,求n最大值
            首先觀察下前面那個(gè)分式,由于n和n-1互質(zhì),所以n^n和(n-1)^n也互質(zhì),分式結(jié)果要為一個(gè)整數(shù),f(n)+n-1中必須含有因子n^n;換句話說(shuō),f(n)+n-1>n^n,題目中給的f(n)可以用32位整數(shù)表示,那么n必然小于12!
            下面不用說(shuō)什么了,暴力吧,肯定0MS了~不過(guò)為了完美,n^n我用了二進(jìn)制快速冪~具體看代碼吧

            代碼:
             1 Source Code
             2 Problem: 1309        User: yzhw
             3 Memory: 392K        Time: 0MS
             4 Language: G++        Result: Accepted
             5 
             6     Source Code
             7 
             8     # include <cstdio>
             9     using namespace std;
            10     long long pow(int a,int b)
            11     {
            12         long long ans=1,t=a;
            13         while(b)
            14         {
            15             if(b&1) ans*=t;
            16             t*=t;
            17             b>>=1;
            18         }
            19         return ans;
            20     }
            21     int main()
            22     {
            23         //freopen("input.txt","r",stdin);
            24         int n;
            25         while(scanf("%d",&n)!=EOF&&n>=0)
            26         {
            27             int ans=-1,i;
            28             for(i=2;i<=12;i++)
            29             {
            30                 long long t=n;
            31                 t+=i-1;
            32                 long long t1=pow(i,i),t2=pow(i-1,i);
            33                 if(t%t1==0)
            34                 {
            35                     t=t/t1*t2-i+1;
            36                     if(t>=0&&t%i==0) ans=i;
            37                 }
            38             }
            39             if(ans==-1) printf("%d coconuts, no solution\n",n);
            40             else printf("%d coconuts, %d people and 1 monkey\n",n,ans);
            41         }
            42         return 0;
            43     }
            44 
            45 

            posted on 2011-07-19 00:10 yzhw 閱讀(227) 評(píng)論(0)  編輯 收藏 引用 所屬分類: numberic

            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導(dǎo)航

            統(tǒng)計(jì)

            公告

            統(tǒng)計(jì)系統(tǒng)

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            亚洲精品国产字幕久久不卡 | 国产精品九九久久免费视频 | 亚洲国产另类久久久精品| 91久久成人免费| 精品无码久久久久久国产| 欧美一级久久久久久久大| 久久综合九色综合网站| 丰满少妇人妻久久久久久| 久久激情五月丁香伊人| 亚洲欧洲日产国码无码久久99| 免费精品国产日韩热久久| 国产成人精品久久一区二区三区 | 日本五月天婷久久网站| 一本综合久久国产二区| 亚洲精品高清久久| 国产福利电影一区二区三区久久久久成人精品综合 | 怡红院日本一道日本久久| 久久精品国产99国产电影网| 亚洲第一永久AV网站久久精品男人的天堂AV | 久久久久亚洲av成人网人人软件| 99久久er这里只有精品18| 久久久国产精品网站| 色8久久人人97超碰香蕉987| 午夜精品久久久久9999高清| 久久青青草视频| 99999久久久久久亚洲| 久久久网中文字幕| 久久99毛片免费观看不卡| 久久久久久无码国产精品中文字幕| 亚洲精品无码久久久| 国产91色综合久久免费分享| 久久精品成人影院| 色欲综合久久中文字幕网| 国产国产成人久久精品| 久久久久亚洲AV无码专区体验| 久久久国产视频| 一本久久久久久久| 无码人妻少妇久久中文字幕蜜桃| 国产精品日韩欧美久久综合| 精品免费久久久久久久| 久久只有这里有精品4|