zoukankan      html  css  js  c++  java
  • The 13th Zhejiang Provincial Collegiate Programming Contest

    The Lucky Week

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date.

    There was one day Edward suddenly found that if Monday was the 1st, 11th or 21st day of that month, he could remember the date clearly in that week. Therefore, he called such week "The Lucky Week".

    But now Edward only remembers the date of his first Lucky Week because of the age-related memory loss, and he wants to know the date of the N-th Lucky Week. Can you help him?

    Input

    There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:

    The only line contains four integers Y, M, D and N (1 ≤ N ≤ 109) indicating the date (Y: year, M: month, D: day) of the Monday of the first Lucky Week and the Edward's query N.

    The Monday of the first Lucky Week is between 1st Jan, 1753 and 31st Dec, 9999 (inclusive).

    Output

    For each case, print the date of the Monday of the N-th Lucky Week.

    Sample Input

    2
    2016 4 11 2
    2016 1 11 10
    

    Sample Output

    2016 7 11
    2017 9 11
    
    题意:当日期为 1,11,21 并且当天为周一时 认为这一周为Lucky Week
    给出起始lucky week 问之后第N个lucky week的 日期

    题解:1.暴力找循环节 每400年中有2058个lucky week
    2.然后就是暴力

     1  #include<iostream>
     2  #include<cstring>
     3  #include<cstdio>
     4  #include<queue>
     5  #include<stack>
     6  #include<map>
     7  #include<set>
     8  #include<algorithm>
     9  #define LL __int64
    10  #define pi acos(-1.0)
    11  #define mod 1
    12  #define maxn 10000
    13  using namespace std;
    14  int  month1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    15  int  month2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    16  bool  year(int ye)
    17  {
    18      if((ye%4==0&&ye%100!=0)||ye%400==0)
    19       return true;
    20       return false;
    21  }
    22  int t;
    23  int y,m,d,n;
    24  int main()
    25  {
    26    while(scanf("%d",&t)!=EOF)
    27    {
    28        for(int i=1;i<=t;i++)
    29        {
    30            scanf("%d %d %d %d",&y,&m,&d,&n);
    31            int exm1=n/2058;
    32            exm1=exm1*400;
    33            int exm2=n%2058;
    34            while(exm2)
    35            {
    36                if(d==1||d==11||d==21)
    37                exm2--;
    38                 if(exm2==0)
    39                 break;
    40                if(year(y))
    41                 {
    42              d=d+7;
    43                 if(month2[m]<d)
    44                   {
    45                   d=d-month2[m];
    46                   m=m+1;
    47                 }
    48                 if(m>12)
    49                   {
    50                       y=y+1;
    51                       m=1;
    52                 }
    53              }
    54              else
    55              {
    56                  d=d+7;
    57                 if(month1[m]<d)
    58                   {
    59                 d=d-month1[m];
    60                 m=m+1;
    61                 }
    62                 if(m>12)
    63                   {
    64                       y=y+1;
    65                       m=1;
    66                 }
    67              }
    68         }
    69         cout<<y+exm1<<" "<<m<<" "<<d<<endl;           
    70     }
    71    }    
    72     return 0;
    73  }


    Lucky Week

  • 相关阅读:
    第27篇-虚拟机字节码指令之操作数栈管理指令
    第26篇-虚拟机对象操作指令之putstatic
    第25篇-虚拟机对象操作指令之getfield
    第24篇-虚拟机对象操作指令之getstatic
    第23篇-虚拟机字节码指令之类型转换
    第22篇-虚拟机字节码之运算指令
    第20篇-加载与存储指令之ldc与_fast_aldc指令(2)
    第19篇-加载与存储指令(1)
    第18章-x86指令集之常用指令
    第17章-x86-64寄存器
  • 原文地址:https://www.cnblogs.com/hsd-/p/5425042.html
Copyright © 2011-2022 走看看