The Lucky Week(打表找规律)

6人阅读 评论(0) 收藏 举报
分类:
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 YMD 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

Author: GAN, Tiansheng

Source: The 13th Zhejiang Provincial Collegiate Programming Contest

题意:我们认为日期的天数为1,11,21,并且是周一的为Lucky Week;现在给出第一个lucky week的日期,求第N个的lucky week;

1:四百年一轮回,从闰年和平年的判定可以推出 

2:由上一条可以用程序判断出每四百年有2058个天为1,11,21的星期一。(打表)

打表找规律:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;
const int maxn  = 1e5+7;

int y, m, d, n;
int rm[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int brm[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool ru(int c) {
    if(c%400 == 0) return true;
    else if(c%100 != 0 && c%4 == 0) return true;
    else return false;
}

void solve()
{
    if(ru(y)) {
        if(d > rm[m]) {
            d -= rm[m];
            m++;
        }
    } else {
        if(d > brm[m]) {
            d -= brm[m];
            m++;
        }
    }
    if(m > 12) {
                m = 1;
                y++;
    }
}




int main()
{
    while(1) {
        scanf("%d%d%d", &y, &m, &d);
        int sum = 0, a = y,b = m, c = d;
        while(1)
        {
            if(d == 1||d == 11||d == 21) {
                    sum++;
            }
            d += 7;
            solve();
            if((y - a>= 400)&&(m >= b)&&(d >= c)) break;
        }
        cout << sum << endl;
    }
    return 0;
}



代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;
const int maxn  = 1e5+7;

int y, m, d, n;
int rm[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int brm[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool ru(int c) {
    if(c%400 == 0) return true;
    else if(c%100 != 0 && c%4 == 0) return true;
    else return false;
}

void solve()
{
    if(ru(y)) {
        if(d > rm[m]) {
            d -= rm[m];
            m++;
        }
    } else {
        if(d > brm[m]) {
            d -= brm[m];
            m++;
        }
    }
    if(m > 12) {
                m = 1;
                y++;
    }
}


int main() {
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d%d", &y, &m, &d, &n);
        y += (n/2058) * 400;
        n %= 2058;

        while(n)
        {
            if(d == 1||d == 11||d == 21) n--;
            if(n == 0) break;
            d += 7;
            solve();
        }
        printf("%d %d %d\n", y, m, d);
    }
}


查看评论

ZOJ 3939 The Lucky Week 找规律打表

ZOJ Problem Set - 3939 The Lucky Week Time Limit: 2 Seconds Memory Limit: 65536 KBEdward, the...
  • hjt_fathomless
  • hjt_fathomless
  • 2016-04-25 23:49:59
  • 507

ZOJ 3939The Lucky Week<模拟/暴力>

题意:我们认为日期的天数为1,11,21,并且是周一的为Lucky Week;现在给出第一个lucky week的日期,求第N个的lucky week; //1:四百年一轮回,从闰年和平年的判定可以...
  • M___er
  • M___er
  • 2016-05-22 19:07:51
  • 583

zoj 3939 The Lucky Week(打表找循环节)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3939  题意:给你一个定义,幸运周,如果周一是某个月的1号,11号或...
  • Miracle_ma
  • Miracle_ma
  • 2016-04-24 21:45:03
  • 756

ZOJ-3939-The Lucky Week【13th浙江省赛】【找规律】

ZOJ-3939-The Lucky Week
  • loy_184548
  • loy_184548
  • 2016-04-24 10:09:56
  • 941

ZOJ 3939 The Lucky Week 2016省赛

The Lucky Week Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the headmaster of t...
  • zcj5027
  • zcj5027
  • 2016-04-24 20:47:59
  • 885

ZOJ 3939 The Lucky Week (打表预处理/找规律)

题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115189#problem/C 代码: #include #include ...
  • qq_32473657
  • qq_32473657
  • 2016-05-07 16:46:29
  • 378

bzoj2405 数字 打表找规律

这题考试的时候就切了。刚开始看到,以为是什么矩阵乘法之类的,但是感觉好像没有递推的性质。 想了半天没有什么想法,然后就想着打个表试试看吧。 先打了D的表,发现好像计算和用(n-1)%9+1就可以了...
  • qq_35866453
  • qq_35866453
  • 2017-07-15 21:03:30
  • 228

【NOIP 模拟题】求和 (打表找规律+递推)

一地落花散、散尽纵横的纷繁
  • reverie_mjp
  • reverie_mjp
  • 2016-08-26 20:50:08
  • 761

HDU 5793 A Boring Question (打表找规律)

m,n都是1e9的数据范围,直接解不太可能,试着打表看一下小数据,结果规律很明显 就是求 m^0 + m^1 + m^2 + ... + m^n 即一个q为m的等比数列求和。 /* *********...
  • AngOn823
  • AngOn823
  • 2016-08-05 09:05:10
  • 333

The Lucky Week

The Lucky Week Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the headmaster of ...
  • wanghandou
  • wanghandou
  • 2016-04-24 09:36:02
  • 301
    个人资料
    持之以恒
    等级:
    访问量: 4559
    积分: 2238
    排名: 2万+
    文章存档
    最新评论