• <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>
            posts - 43,  comments - 9,  trackbacks - 0
            http://acm.hdu.edu.cn/showproblem.php?pid=1005
            A number sequence is defined as follows:
            f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
            Given A, B, and n, you are to calculate the value of f(n).
            1 <= A, B <= 1000, 1 <= n <= 100,000,000

            解:
            f(n) = (A * f(n - 1) + B * f(n - 2)) %7
                  = (A * f(n - 1) %7 + B * f(n - 2) %7) %7
            所以對于給定的A和B,可以先打表,找出數(shù)列的循環(huán)部分. 鴿巢原理知,狀態(tài)總數(shù)不會超過7*7
            注意循環(huán)節(jié)不一定從f(3)開始...

             1#include <iostream>
             2using namespace std;
             3
             4int a,b,n,x,y,l,h,m[7][7],q[300];
             5int main(){
             6    while(scanf("%d%d%d",&a,&b,&n)!=EOF && (a||b||n)){
             7        memset(m, 0sizeof(m));
             8        q[1= q[2= 1;
             9        x = y = 1; l=3;
            10        while(m[x][y]==0)//該狀態(tài)還未經(jīng)歷過,則擴(kuò)展
            11            q[l] = (a*x+b*y)%7;
            12            m[x][y] = l;
            13            y = x;
            14            x = q[l++];
            15        }

            16        //此時(shí),q[1h-1]為前面的非循環(huán)部分
            17         //q[hl-1]為循環(huán)節(jié)
            18        h = m[x][y]; //循環(huán)節(jié)的起始位置
            19        if(n<h) printf("%d\n",q[n]);
            20        else printf("%d\n",q[((n-h)%(l-h))+h]);
            21    }

            22    return 0;
            23}

            posted on 2009-04-25 11:55 wolf5x 閱讀(917) 評論(0)  編輯 收藏 引用 所屬分類: acm_icpc
            <2011年8月>
            31123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            "Do not spend all your time on training or studying - this way you will probably become very exhausted and unwilling to compete more. Whatever you do - have fun. Once you find programming is no fun anymore – drop it. Play soccer, find a girlfriend, study something not related to programming, just live a life - programming contests are only programming contests, and nothing more. Don't let them become your life - for your life is much more interesting and colorful." -- Petr

            留言簿(3)

            隨筆分類(59)

            隨筆檔案(43)

            cows

            搜索

            •  

            最新評論

            評論排行榜

            久久婷婷综合中文字幕| 性色欲网站人妻丰满中文久久不卡| 久久精品国产半推半就| 久久er国产精品免费观看8| 国产香蕉久久精品综合网| 99精品国产在热久久无毒不卡| 久久av高潮av无码av喷吹| 日韩精品无码久久久久久| 久久久WWW成人| 97精品久久天干天天天按摩| 九九久久精品无码专区| 精品国际久久久久999波多野| 日韩久久久久中文字幕人妻| 九九99精品久久久久久| 伊人久久大香线蕉AV色婷婷色| 色综合久久最新中文字幕| 亚洲精品tv久久久久久久久| 久久精品二区| 999久久久免费国产精品播放| 久久人妻AV中文字幕| 精品国产婷婷久久久| 国产精品久久久久影院色 | 久久精品中文无码资源站| 久久婷婷色综合一区二区| 久久青青草原国产精品免费| 久久狠狠高潮亚洲精品| 亚洲国产欧美国产综合久久 | 国产产无码乱码精品久久鸭| 久久青青草视频| 手机看片久久高清国产日韩| 久久精品国产福利国产琪琪| 亚洲国产精品热久久| 伊人丁香狠狠色综合久久| 久久综合久久综合久久综合| 久久国产精品成人影院| 久久99精品久久只有精品| 性欧美大战久久久久久久久| 久久亚洲AV成人无码软件| 久久天天躁夜夜躁狠狠| 久久亚洲精品成人无码网站| 2021最新久久久视精品爱|