520的今天表白CUIT6301所有成员。此事无关风与月。那一份执着与坚持,愈久弥新。
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).

Output
For each case, print the date of the Monday of the N-th Lucky Week.

Sample Input
2
2016 4 11 2
2016 1 11 10
Sample Output
2016 7 11
2017 9 11
我是一只酸菜鱼,又酸又菜又多余。题意:找出第N个满足从所给日期开始算的周一是1、11、21号的日期。场上wa了一两个小时的我,让我独自在风中飘零。暴力算,超时+wa会紧跟你。AC思路:400年为一个周期,求出400年有多少天周一是1、11、21号(cnt计数),然后用N/cnt,求出有多少个是满足周期的(Count),在Y的基础上加上400Count,剩下的年月日,他肯定不会超过一个周期。Then就直接枚举过。*

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>using namespace std;int t,month,day,m,cnt;
long long int year;
int a[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};void init(){int cas = 0;for(int i = 1753 ; i <= 1753 + 399 ; i++){//四00年一个周期((i % 100 != 0 && i % 4 == 0) || i % 400 == 0) ?a[2] = 29:a[2] = 28;for(int j = 1 ; j <= 12 ; j++)for(int k = 1 ; k <= a[j] ; k++){++cas;if((k == 1 || k == 11 || k == 21) && cas % 7 == 1)  ++cnt;}}
}int main(){init();scanf("%d",&t);for(int pp = 0 ; pp < t ; pp++){scanf("%lld%d%d%d",&year,&month,&day,&m);int Count = m/cnt;int remain = m - Count*cnt;year += 400*Count;int cas = 0,k,j;
//        cout<<year<<endl;
//        cout<<"aaaaaaaa"<<endl;for(long long int i = year ; i <= year + 400 ; i++){((i % 100 != 0 && i % 4 == 0) || i % 400 == 0)? a[2] = 29:a[2] = 28;for(j = month ; j <= 12 ; j++){for(k = day; k <= a[j] ; k++){++cas;if((k == 1 || k == 11 || k == 21) && cas % 7 == 1){remain--;// printf("%lld %d %d\n",year,month,day);}if(remain == 0){year = i;month = j;day = k;break;}}if(!remain) break;day = 1;}if(!remain) break;month = 1;}printf("%lld %d %d\n",year,month,day);}return 0;
}

ZOJ - 3939相关推荐

  1. ZOJ - 3939 The Lucky Week【简单方法】

    题目 传送门 Sample Input 2 2016 4 11 2 2016 1 11 10 Sample Output 2016 7 11 2017 9 11 题意:t组数据,给出四个数,x,y,z ...

  2. 【打表找循环节】ZOJ - 3939 The Lucky Week

    Step1 Problem: 幸运日指,星期一是1 or 11 or 21号.给出第一个幸运日时间,问第n个幸运日的时间. 例如: 2016 4 11 2 输出: 2016 7 11 数据范围: 时间 ...

  3. ZOJ 3939 The Lucky Week (打表预处理/找规律)

    题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115189#problem/C 代码: #include <cstdio> ...

  4. The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)

      前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率. 结果后面2题都由波神做掉,学长带我们飞~ 终榜 官方题解   ZOJ 3946 Highway ...

  5. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  6. zoj 1204 Additive equations

    ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...

  7. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  8. 模拟 ZOJ 3878 Convert QWERTY to Dvorak

    题目传送门 1 /* 2 模拟:手敲map一一映射,累! 3 除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:) 4 */ 5 #include <cstdio> 6 ...

  9. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 1 /* 2 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 3 矩阵连乘积问题,DP解决:状态转移方程: 4 dp[i][j] = min (dp[i][k] + dp[k+1] ...

  10. ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)

    ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...

最新文章

  1. oracle 分页写法
  2. curl 请求没反应_理解Redis的反应堆模式
  3. 跳板机连接数据库_跳板数据科学职业生涯回顾
  4. Xamarin效果第十四篇之玩耍GIS
  5. Jenkins中执行batch和Python
  6. python软件安装及设置_Python 基础知识及安装配置
  7. 跨部门不配合工作_同事不配合工作,划水甚至推诿,该怎么体现你的手腕
  8. vi单文件操作常用命令
  9. 【转】编写高质量代码改善C#程序的157个建议——建议33:避免在泛型类型中声明静态成员...
  10. Doom3 引擎渲染管线分析
  11. NSIS 头文件介绍_TextFunc.nsh(2)
  12. H.265之三 -帧内预测(3)
  13. GreenPlum 大数据平台--运维(三)
  14. wapl是什么功能?启用有什么用
  15. Linux下退出vi编辑模式
  16. Bert—SST-2
  17. wince挂起和唤醒(suspend/wakeup)
  18. android 群控 网络 adb,逍遥安卓模拟器群控软件用的ADB
  19. git命令行拉取合并代码流程
  20. 分享一篇文章——2013年《意林》 华文 《二十岁无资本无未来》 值得我们思考一生

热门文章

  1. 零基础元宇宙AR Avatar制作教程
  2. php导入word文件怎么打开,phpword 导入word
  3. 史上最全常见前端大厂面试知识点汇总【已过字节, 腾讯teg,华为,网易】
  4. 基于K8S的容器化PaaS平台建设
  5. 揭秘前端工程师未来就业方向,年薪50w不是梦!
  6. HDU 6164 Dying Light(计算几何)
  7. Chrome浏览器常用快捷键总结
  8. mindspore| lenet模型 推理过程记录
  9. 如何打开.exe文件
  10. 岳不群认识独孤九剑吗?