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 % ;
if (x == ) return ;
else return x;
}
int f(int yy)
{
if (yy % == || (yy % != && yy % == ))
{
return ;
}
else return ;
}
int main()
{
int y = ;
int m = , d = ;
int x = ;
int k = ;
node a;
a.y = ;
a.m = ;
a.d = ;
v.push_back(a);
for (int i = ; i <= ; i++)//打表
{
while ()
{
if (d == )
{
if (m == || m == || m == || m == || m == || m == || m == )
{
x = xq(x + );
}
else if (m != )
{
x = xq(x + );
}
else
{
if (f(y)) x = xq(x + );
else x = xq(x + );
}
if (m == )
{
m = ;
d = ;
y++;
}
else
{
m++;
d = ;
}
if (x == )
{
node a;
a.y = y;
a.m = m;
a.d = d;
v.push_back(a);
break;
}
continue;
}
if (d == || d == )
{
d = d + ;
x = xq(x + );
if (x == )
{
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 / ;
n= n % ; int yy = y;
while (y >= )
{
y = y - ;
}
for (int i = ; 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*, v[i + n].m, v[i + n].d);
break;
}
} }
return ;
}

2016第十三届浙江省赛 D - The Lucky Week的更多相关文章

  1. ZOJ 3781 - Paint the Grid Reloaded - [DFS连通块缩点建图+BFS求深度][第11届浙江省赛F题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Time Limit: 2 Seconds      Me ...

  2. ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds      Me ...

  3. ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds      Me ...

  4. 第15届浙江省赛 E LIS

    LIS Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge DreamGrid is learning the LI ...

  5. 第十五届浙江省赛 F Now Loading!!!

    Now Loading!!! Time Limit: 1 Second      Memory Limit: 131072 KB DreamGrid has  integers . DreamGrid ...

  6. 第15届浙江省赛 D Sequence Swapping(dp)

    Sequence Swapping Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao has just found a strange s ...

  7. 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

    2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...

  8. 2016 CCPC 东北地区重现赛

    1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08   HDU5929 Basic Data Structure    模拟,双端队列 1.题意:模拟一个栈的操 ...

  9. 第七届河南省赛10403: D.山区修路(dp)

    10403: D.山区修路 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 69  Solved: 23 [Submit][Status][Web Bo ...

随机推荐

  1. 在Linux终端中查看公有IP的方法详解

    首先回顾一下一般的查看IP的命令: ifconfigLinux查看IP地址的命令--ifconfigifconfig命令用于查看和更改网络接口的地址和参数 $ifconfig -a  lo0: fla ...

  2. 最短路径Dijkstra模板

    算法思想:把所有的边分成两个集合A,B.集合A表示已经求出最短路径的点,不断扩展集合A,减少集合B.每一扩展就从结合B中找出到源点距离最短的点,加入到A. dis[i]数组代表从出发点到j的距离: m ...

  3. ActiveMQ部署和503的错误

    最近部署ActiveMQ的时候,发现有的服务器可以打开后台管理网址,有的服务器无法打开,Jetty报503 Service Unavailable. 搞了很久终于发现了问题,现将部署和解决过程做笔记如 ...

  4. 【P2405】方格取数问题加强版(费用流)

    考虑如何建图.还是老样子先拆点,然后把每两个点之间连接两条边,一条流量为1,费用为-点权,处理是否走这个点.一条流量无限,没有费用,因为哪怕一个点选过了,它的地方还是可以重复走过去的. 然后把经由一个 ...

  5. HTTP 指纹识别v0.1

    // Winhttp.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> #include ...

  6. Web 应用程序项目与 Visual Studio 中的网站项目的异同

    要查看英语原文,请勾选“英语”复选框.也可将鼠标指针移到文本上,在弹出窗口中显示英语原文. 翻译 英语 本文档已存档,并且将不进行维护. Web 应用程序项目与 Visual Studio 中的网站项 ...

  7. poj 1061 青蛙的约会 扩展欧几里德

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K       Description 两 只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们 ...

  8. Http协议与生命周期

    一.Http知识:    1.基于socket        浏览器(格式一)        web服务器(格式一)        MYSQL客户端(格式二)        MYSQL服务端(格式三) ...

  9. 对象存储API

    使用对象存储API步骤: 1.购买腾讯云对象存储(COS)服务 2.在腾讯云 对象存储控制台 里创建一个Bucket 3.在控制器 个人API密钥 页里获取APPID,SecretID,SecretK ...

  10. java 读取src下的配置文件

    很多时候,我们都将配置文件放在eclipse的src目录下,这个位置,相当于,当导出可执行jar包后,配置文件放在和jar同级的目录中,比如jar包放在/opt目录下,则配置文件放在/opt下,则ja ...