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 ;
}

最新文章

  1. LK产品如何提高通信速率
  2. PageContext
  3. php快速排序
  4. 安装完 MySQL 后必须调整的 10 项配置
  5. entity framework 动态条件
  6. U-Boot在FL2440上移植(四)----支持网卡DM9000和烧写yaffs文件系统
  7. 【Java基础】选择排序、冒泡法排序、二分法查找
  8. ice 有道德的黑客!
  9. hibernate动态切换数据源
  10. Angular4 后台管理系统搭建(9) - 用自定义angular指令,实现在服务端验证
  11. 重构手法之Extrct Method(提炼函数)
  12. Golang学习--TOML配置处理
  13. 潜在风险的频次vs潜在风险的严重影响的程度(以及恢复)
  14. Hello_Git!!!(Git的安装)
  15. java 生成随机校验码
  16. .Net Core连接RabbitMQ集群
  17. 要成为linux网站运维工程师必须要掌握的技能
  18. [Boolan-C++学习笔记]第二周整理
  19. ew代理实战
  20. Codeforces Educational Round 57

热门文章

  1. 关于Kinect音频开发的探究
  2. python批量修改文件名称
  3. XXL-Job高可用集群搭建
  4. Oracle数据库连接生成DataX的job-Json
  5. ML 线性回归Linear Regression
  6. HDU4819 Mosaic
  7. aodh M版本新特性 - queue between alarm evaluator and alarm notifier
  8. $.ajax应用之请求头headers
  9. Python爬虫之BeautifulSoup的用法
  10. Adobe Reader 的直接下载地址