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 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).
<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的更多相关文章
- 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 ...
- ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds Me ...
- ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds Me ...
- 第15届浙江省赛 E LIS
LIS Time Limit: 1 Second Memory Limit: 65536 KB Special Judge DreamGrid is learning the LI ...
- 第十五届浙江省赛 F Now Loading!!!
Now Loading!!! Time Limit: 1 Second Memory Limit: 131072 KB DreamGrid has integers . DreamGrid ...
- 第15届浙江省赛 D Sequence Swapping(dp)
Sequence Swapping Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a strange s ...
- 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告
2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- 第七届河南省赛10403: D.山区修路(dp)
10403: D.山区修路 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 69 Solved: 23 [Submit][Status][Web Bo ...
随机推荐
- Service Meth and SideCar
本文转自:http://philcalcado.com/2017/08/03/pattern_service_mesh.html SideCar: SideCar就是与Application一起运行的 ...
- IntelliJ Idea 快捷键精选
Alt+Enter,导入包,自动修正Ctrl+F,查找文本Alt+Up/Down,上/下移一行:在方法间快速移动定位:与光标位置有关Alt+Shift+Up,多次up可选中一行Ctrl+X,剪切行Ct ...
- tyvj 1057 金明的预算方案 背包dp
P1057 金明的预算方案 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2006 提高组 第二道 描述 金明今天很开心,家里购置的新房就要领钥匙了 ...
- dp1--乘积最大
dp1--乘积最大 一.心得 1.用excel填数组很方便 2. dp就是填表 找状态就是缩小规模 找状态转移方程就是 找状态的最后一次关系 二.题目 8782:乘积最大 查看 提交 统计 提问 总时 ...
- hdu 1517 A Multiplication Game(必胜态,必败态)
A Multiplication Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- LVM MBR分区(装载)
必须有至少一个主分区(P),主分区个数+扩展分区个数<= 4个. 创建完主分区,可以创建扩展分区(E),扩展分区可以有1个,或者没有(扩展分区). 主分区(Primary Partion)可以 ...
- 熟练使用IDT
一些很基础的操作,现在基本都了然于胸了.主要还是多练习.多去写,多去看别人的.后来才能更加的熟悉.工具这东西,越是经常使用,越是得心应手.虽然现在还是很菜.好歹也会了不少了.勤能补拙,不要太看低别人, ...
- c++primer 第五章编程练习答案
5.9.1 #include<iostream> int main() { using namespace std; ; cout << "input first i ...
- 分布式_理论_06_ 一致性算法 Raft
一.前言 五.参考资料 1.分布式理论(六)—— Raft 算法 2.分布式理论(六) - 一致性协议Raft
- GEF入门实例_总结_05_显示一个空白编辑器
一.前言 本文承接上一节:GEF入门实例_总结_04_Eclipse插件启动流程分析 在第三节( GEF入门实例_总结_03_显示菜单和工具栏 ),我们创建了菜单和工具栏. 这一节,我们来实现:点击 ...