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 ...
随机推荐
- spring boot 默认配置bug
问题场景:请求很耗时,当一次请求完成后,之后的20秒内的请求很快速,在之后的第一个请求很慢! 每隔一段时间,请求就会出发解压jar的操作,不确定是操作系统的问题还是sping-boot的bug &qu ...
- Tensorflow 从零开始
1.安装pip pip是一个用于管理和安装Python包的工具,类似于LINUX 的yum命令一样! 命令(Ubuntu系统):sudo apt-get install python-pip 验证安装 ...
- strip_tags--php
函数剥去字符串中的 HTML.XML 以及 PHP 的标签 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. allow 可选.规定允许的标签.这 ...
- Word 2010怎么自动添加文献引用
1.将光标移至在需要添加引用的地方,比如我下图中在这段文字最后添加一个引用(为了方便说明) 2.(2010版本) 3.点击上面的“引用”,然后点击蓝圈里面的小图标,出现下面对话框,并设置成如图,点 ...
- 维度属性的KeyColumns,NameColumn和ValueColumn
维度的每一个属性都有KeyColumns,NameColumn和ValueColumn 1,如何理解KeyColumns,NameColumn和ValueColumn?对一行记录有不同的标识列,但 ...
- python中常用的文件和目录操作(一)
常用的文件操作 1. 打开文件 open,它是一个内置函数,可以直接调用 语法:file object = open(file_name, [access_mode]),这里我们会创建一个file对象 ...
- python向数据库插入中文乱码问题
1.python向数据库插入中文乱码问题 直接手动insert into 中文 不乱码,但是用程序跑起来就乱码. conn =MySQLdb.connect(host="127.0.0.1& ...
- C#中的线程(一)入门
C#中的线程(一)入门 Keywords:C# 线程Source:http://www.albahari.com/threading/Author: Joe AlbahariTranslator: ...
- JVM_总结_02_Java技术体系
一.前言 此系列随笔是针对<深入理解Java虚拟机:JVM高级特性与最佳实践 第2版>的总结 上一节,我们搭建好了java的开发环境,这一节,我们来看Java的技术体系 二.Java技术体 ...
- kylin_异常_01_java.io.FileNotFoundException: /developer/apache-kylin-2.3.0-bin/tomcat/conf/.keystore
一.异常现象 kylin安装完,启动后,控制正常,kylin后台也能正常访问.但是去看kylin的日志,却发现报错了: SEVERE: Failed to load keystore type JKS ...