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. windows10 搜索桌面搜索功能失效的解决

    windows桌面的搜索框用起来很方便,很多时候直接把不常用的程序的快捷方式删掉,直接从搜索框搜索就可以,但是这两天突然不能用了,今天晚上找了一下原因,终于弄好了. 参考知乎上面的陈滔滔的方法: ht ...

  2. CSU 1786 莫队+KDTree

    题意 给出n个二维点(2e5) 和 q个询问(1e4) 每个询问给lr 问点l到r间有多少对点的曼哈顿距离<=d 点的坐标<=108 想出了莫队算法 复杂度n^1.5 看起来很科学 但是每 ...

  3. tp后台注册登录配置项

    1.在application目录下Common/Conf/config.php中 2-17行,首先判断在data目录下有没有特意设置的db.php, config.php,route.php,如果有就 ...

  4. boot小知识

    lg 大, md 中等, sm 小, xs 极小. 可以单独用,也可以混合用,不同的屏幕用不同的比例. push ,pull 推拉.这个不实用. row里面可以嵌套实用row. 挤不下的时候,就会自动 ...

  5. 语音02_Delphi

    网址 :http://www.exceletel.com/support/whtpapers/speech/delphi.htm Installing the Microsoft SAPI speec ...

  6. mvn 用指定setting.xml 执行指定pom.xml

    mvn package -f pom.xml -s setting.xml clean install

  7. 我的java mvc

    mint mvc 并不是我原创的.她的基础是廖雪峰老师的webwind mvc. webwind是廖老师模仿spring的一个 rest 风格的 mvc 框架,功能简单,但是mvc的核心功能基本具备了 ...

  8. CentOS下用于查看系统当前登录用户信息的4种方法

    作为系统管理员,你可能经常会(在某个时候)需要查看系统中有哪些用户正在活动.有些时候,你甚至需要知道他(她)们正在做什么.本文为我们总结了4种查看系统用户信息(通过编号(ID))的方法. 1. 使用w ...

  9. 2017-03-05 CentOS中结合Nginx部署dotnet core Web应用程序

    Visual Studio Live 倒计时2天,当然这是美国倒计时两天,中国应该是在3月8日的凌晨,正值"3.8妇女节".提前祝广大的女性同志节日快乐,当然还有奋斗在一线的程序媛 ...

  10. webservice 交错数组

    net webservices public DataSet SelectOPQuestionByWhere(string strWhere, string[][] strArry) { if (!k ...