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 ...
随机推荐
- poj2528线段树解题报告,离散化+线段树
题目网址:http://poj.org/problem?id=2528 题意: n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=1 ...
- CodeForces 266E More Queries to Array...(线段树+式子展开)
开始觉得是规律题的,自以为是的推了一个规律,结果测试数据都没过....看了love神的博客才发现只是把式子展开就找到规律了.不过挺6的是我虽然想错了,但是维护的的东西没有错,只是改改(改了进两个小时好 ...
- 做一个完整的Java Web项目需要掌握的技能
最近自己做了几个JavaWeb项目,有公司的商业项目,也有个人做着玩的小项目,写篇文章记录总结一下收获,列举出在做项目的整个过程中,所需要用到的技能和知识点,带给还没有真正接触过完整Java Web项 ...
- openstack-ansible -- 3 Target hosts
Installing the operating system Install the Ubuntu Server 14.04 (Trusty Tahr) LTS 64-bit operating s ...
- MySql基础学习-Sql约束
1.主键约束(PRIMARY KEY) 主键 (PRIMARY KEY)是用于约束表中的一行,作为这一行的唯一标识符,在一张表中通过主键就能准确定位到一行,因此主键十分重要.主键不能有重复且不能为空. ...
- git将代码上传到coding分支
分支 我理解的分支 分支,简单地讲就是一个项目的不同分支存放不同的代码,这样的话一个项目就有了几分代码,但是最终的代码一般放在主分支里面,即master分支里,分支在实际中可以方便的隔离开发. 假设你 ...
- js中scrollIntoView()的用法
一. 什么是scrollIntoView scrollIntoView是一个与页面(容器)滚动相关的API 二. 如何调用 element.scrollIntoView() 参数默认为true 参数为 ...
- [非原创] 常用加密算法整理 AES/SSL(一)
前言: 在伟大的计算机科学家研究下,发明了许多的加密算法,以下做个简答的描述: 一.分类 加密算法分为两种:单向加密.双向加密. 单向加密,不可逆的加密算法,只能加密不能解密: 双向加密,由对称性加密 ...
- TCP/IP详解学习笔记(3)-IP协议,ARP协议,RARP协议【转】
转自:http://blog.csdn.net/goodboy1881/article/details/668556 把这三个协议放到一起学习是因为这三个协议处于同一层(网际层),ARP协议用来找到目 ...
- 从一个简单的Tab切换开始——与AJAX的结合
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...