• <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 閱讀(211) 評論(0)  編輯 收藏 引用 所屬分類: others

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久夜色tv网站| 欧洲国产伦久久久久久久| 色噜噜狠狠先锋影音久久| 久久国产精品免费一区| 亚洲国产视频久久| 精品久久人妻av中文字幕| 久久成人精品| 久久av无码专区亚洲av桃花岛| 国产精品久久久福利| 久久99九九国产免费看小说| 久久免费的精品国产V∧| 精品久久久久久国产牛牛app | 久久精品www人人爽人人| 久久国产成人| 久久中文字幕一区二区| 亚洲精品乱码久久久久久蜜桃图片| 9999国产精品欧美久久久久久 | 青草国产精品久久久久久 | 国内精品久久久久久99蜜桃| 伊人久久大香线蕉综合5g| 久久精品国产亚洲7777| 久久综合丝袜日本网| 国产成人精品久久二区二区| 亚洲中文字幕无码久久综合网| 午夜精品久久久久9999高清| 国产午夜电影久久| 国产999精品久久久久久| 中文字幕亚洲综合久久| 国产综合久久久久| 久久婷婷五月综合色奶水99啪| 成人综合久久精品色婷婷| 亚洲一区精品伊人久久伊人| 久久夜色撩人精品国产| 精品一久久香蕉国产线看播放| 国产精品久久久久久久久鸭| 99re久久精品国产首页2020| 99久久99久久久精品齐齐| 精品久久无码中文字幕| 99国产精品久久| 99国内精品久久久久久久| 人人狠狠综合久久亚洲88|