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

            pku 3393 Lucky and Good Months by Gregorian Calendar 英語閱讀題

            哎。。怎么說呢,這種題目一點細節注意不到就是幾個小時的浪費
            總結下題目吧
            說白了就是計算公歷系統中某年某月的第一天是不是周一、周六、周日以及某年某月的最后一天是不是周五、周六、周日
            關于公歷大家知道的就不說了,說幾點大家可能不知道的
            1、關于閏年
            An year y, y > 1582 and y ≠ 1700, is a leap year if and only if(注意!1700算閏年)
            • y is divisible by 4, and

            • y is not divisible by 100 unless it is divisible by 400.

            An year y, 0 < y < 1582 is a leap year if and only if

            • y is divisible by 4.
            2、關于公歷中有11天的缺失
             11 days are eliminated starting September 3, 1752 in order for people not to rewrite history

            下面就是常規的做法了。。
            統計截止到每一年有多少天,然后將所有的lucky month和good month都找出來,順序存放在數組中,查詢的時候二分減一下就可以了~
            代碼:
             1 # include <iostream>
             2 using namespace std;
             3 int o[]={31,28,31,30,31,30,31,31,30,31,30,31},l[]={31,29,31,30,31,30,31,31,30,31,30,31};
             4 int y[10001];
             5 # include <vector>
             6 # include <algorithm>
             7 # define MON 730124
             8 # define FRI 730121
             9 # define SAT 730122
            10 # define SUN 730123
            11 vector<int> lucky,good;
            12 int main()
            13 {
            14     //init
            15     for(int i=1;i<12;i++)
            16       o[i]+=o[i-1],l[i]+=l[i-1];
            17     y[0]=0;
            18     for(int i=1;i<10000;i++)
            19     {
            20       if(i<1582&&i%4==0||i>1582&&(i%4==0&&i%100!=0||i%400==0)||i==1700)
            21           y[i]=y[i-1]+l[11];
            22       else
            23           y[i]=y[i-1]+o[11];
            24       if(i==1752) y[i]-=11;
            25     }
            26    for(int i=1;i<10000;i++)
            27    {
            28          
            29         int *m;
            30         if(i<1582&&i%4==0||i>1582&&(i%4==0&&i%100!=0||i%400==0)) m=l;
            31         else m=o;
            32         if(i==1752)
            33         {
            34           for(int j=8;j<12;j++) m[j]-=11;
            35         } 
            36         if((y[i-1]+1-MON)%7==0||(y[i-1]+1-SAT)%7==0||(y[i-1]+1-SUN)%7==0) good.push_back(i*12+1);
            37         if((y[i-1]+o[0]-FRI)%7==0||(y[i-1]+o[0]-SAT)%7==0||(y[i-1]+o[0]-SUN)%7==0) lucky.push_back(i*12+1);
            38         for(int j=1;j<12;j++)
            39         {
            40            if((y[i-1]+1+m[j-1]-MON)%7==0||(y[i-1]+1+m[j-1]-SAT)%7==0||(y[i-1]+1+m[j-1]-SUN)%7==0) good.push_back(i*12+j+1);
            41            if((y[i-1]+m[j]-FRI)%7==0||(y[i-1]+m[j]-SAT)%7==0||(y[i-1]+m[j]-SUN)%7==0) lucky.push_back(i*12+j+1);
            42         }     
            43         if(i==1752)
            44         {
            45           for(int j=8;j<12;j++) m[j]+=11;
            46         } 
            47    }
            48    int n;
            49    cin>>n;
            50    while(n--)
            51    {
            52       int y1,m1,y2,m2;
            53       cin>>y1>>m1>>y2>>m2;
            54       cout<<upper_bound(lucky.begin(),lucky.end(),y2*12+m2)-lower_bound(lucky.begin(),lucky.end(),y1*12+m1)<<" "<<upper_bound(good.begin(),good.end(),y2*12+m2)-lower_bound(good.begin(),good.end(),y1*12+m1)<<endl;
            55    }
            56    //system("pause");
            57    return 0;
            58 }
            59 


            posted on 2011-01-06 00:14 yzhw 閱讀(220) 評論(0)  編輯 收藏 引用 所屬分類: others

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

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久青青国产| 99久久婷婷免费国产综合精品| 99久久精品免费| 人妻少妇精品久久| 久久亚洲精品中文字幕| 狠狠色丁香婷婷综合久久来来去 | 777午夜精品久久av蜜臀| 久久精品无码专区免费东京热| 91久久国产视频| 久久亚洲精品成人AV| 亚洲色欲久久久久综合网 | 偷偷做久久久久网站| 亚洲成色999久久网站| 久久丫精品国产亚洲av| 亚洲国产成人精品无码久久久久久综合 | 国产午夜精品久久久久免费视| 国产精品成人无码久久久久久| 久久久久亚洲AV无码麻豆| 久久AⅤ人妻少妇嫩草影院| 久久综合久久综合九色| 中文字幕人妻色偷偷久久| 日韩va亚洲va欧美va久久| 国产精品久久久久久久午夜片| 99re久久精品国产首页2020| 久久精品中文无码资源站| 久久久久国产精品人妻| 亚洲午夜精品久久久久久app| 久久精品视频91| 久久免费视频6| 日韩影院久久| 亚洲精品NV久久久久久久久久| 四虎影视久久久免费观看| 性做久久久久久久久| 一本色道久久综合| 久久综合亚洲色HEZYO社区 | 九九久久99综合一区二区| 久久精品中文无码资源站| 99久久超碰中文字幕伊人| 狠色狠色狠狠色综合久久| 99热成人精品免费久久| 国产精品免费久久|