2016第十三届浙江省赛 D - The Lucky Week

 

D - The Lucky Week

 

 

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).

<h4< dd="">Output

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

<h4< dd="">Sample Input

2
2016 4 11 2
2016 1 11 10

<h4< dd="">Sample Output

2016 7 11
2017 9 11

 

 

题目链接:ZOJ-3939

题目大意:幸运的星期指,星期一为每个月的1 or 11 or 21号。给出第一个幸运星期的时间,问第n个的日期

题目思路:比赛的时候,这道题卡了最久时间。因为刚开始题意理解错了,以为第n个最大是9999年的,于是SF了。

然后是循环节找了很久。。 循环节为400 知道了循环节就比较好写了,还有就是求年份比较绕。每400年里有2058这样的特殊天。

 

#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
struct node
{
    int y, m, d;
};
vector<node>v;
int xq(int x)
{
    x = x % 7;
    if (x == 0) return 7;
    else return x;
}
int f(int yy)
{
    if (yy % 400 == 0 || (yy % 100 != 0 && yy % 4 == 0))
    {
        return 1;
    }
    else return 0;
}
int main()
{
    int y = 1753;
    int m = 1, d = 1;
    int x = 1;
    int k = 1;
    node a;
    a.y = 1753;
    a.m = 1;
    a.d = 1;
    v.push_back(a);
    for (int i = 1; i <= 6060; i++)//打表
    {
        while (1)
        {
            if (d == 21)
            {
                if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
                {
                    x = xq(x + 11);
                }
                else if (m != 2)
                {
                    x = xq(x + 10);
                }
                else
                {
                    if (f(y)) x = xq(x + 9);
                    else x = xq(x + 8);
                }
                if (m == 12)
                {
                    m = 1;
                    d = 1;
                    y++;
                }
                else
                {
                    m++;
                    d = 1;
                }
                if (x == 1)
                {
                    node a;
                    a.y = y;
                    a.m = m;
                    a.d = d;
                    v.push_back(a);
                    break;
                }
                continue;
            }
            if (d == 1 || d == 11)
            {
                d = d + 10;
                x = xq(x + 10);
                if (x == 1)
                {
                    node a;
                    a.y = y;
                    a.m = m;
                    a.d = d;
                    v.push_back(a);
                    break;
                }
                continue;
            }
        }
    }
    /*for (int i = 0; i < v.size(); i++)
    {
        cout << i + 1 << " " << v[i].y << " " << v[i].m << " " << v[i].d << endl;
    }*/
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int y, m, d, n;
        scanf("%d %d %d %d",&y,&m,&d,&n);
        int x;
        n--;
        x = n / 2058;
        n= n % 2058;
        
        int yy = y;
        while (y >= 2153)
        {
            y = y - 400;
        }
        for (int i = 0; i < v.size(); i++)
        {        
                if (v[i].y == y&&v[i].m==m&&v[i].d==d)
                {
                    printf("%d %d %d\n", v[i+n].y+yy-y+x*400, v[i + n].m, v[i + n].d);
                    break;
                }
        }

    }
    return 0;
}

 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蔡军帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值