ZOJ3939-The Lucky Week
2017-05-06 23:12
239 查看
The Lucky Week
Time Limit: 2 Seconds Memory Limit: 65536 KB
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?
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).
Author: GAN, Tiansheng
Source: The 13th Zhejiang Provincial Collegiate Programming Contest
题意:给一日期,如果这个月的1, 11, 21号是星期一没那么那一天是是幸运的,求所给的日期后第n个幸运天的日期
解题思路:直接打表得到400年为一个循环,且400年内的lucky week的个数为2058,然后暴力求解
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
int mon[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int monn[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
bool check(int x)
{
if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0) return 1;
else return 0;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int y, m, d, n;
scanf("%d %d %d %d", &y, &m, &d, &n);
int yy = n / 2058 * 400 + y;
n %= 2058;
int cnt = 0,sum=0,flag=0;
for (int i = yy; ; i++)
{
for (int j = (i == yy) ? m : 1; j < 13; j++)
{
for (int k = (i == yy && j == m) ? d : 1; k < 30; k += 10,sum+=10)
{
if (sum%7==0) cnt++;
if (cnt == n)
{
flag = 1;
printf("%d %d %d\n", i, j, k);
break;
}
}
if (flag) break;
if (check(i)) sum += monn[j] - 20-10;
else sum += mon[j] - 20-10;
}
if (flag) break;
}
}
return 0;
}
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
Author: GAN, Tiansheng
Source: The 13th Zhejiang Provincial Collegiate Programming Contest
题意:给一日期,如果这个月的1, 11, 21号是星期一没那么那一天是是幸运的,求所给的日期后第n个幸运天的日期
解题思路:直接打表得到400年为一个循环,且400年内的lucky week的个数为2058,然后暴力求解
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
int mon[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int monn[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
bool check(int x)
{
if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0) return 1;
else return 0;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int y, m, d, n;
scanf("%d %d %d %d", &y, &m, &d, &n);
int yy = n / 2058 * 400 + y;
n %= 2058;
int cnt = 0,sum=0,flag=0;
for (int i = yy; ; i++)
{
for (int j = (i == yy) ? m : 1; j < 13; j++)
{
for (int k = (i == yy && j == m) ? d : 1; k < 30; k += 10,sum+=10)
{
if (sum%7==0) cnt++;
if (cnt == n)
{
flag = 1;
printf("%d %d %d\n", i, j, k);
break;
}
}
if (flag) break;
if (check(i)) sum += monn[j] - 20-10;
else sum += mon[j] - 20-10;
}
if (flag) break;
}
}
return 0;
}
相关文章推荐
- ZOJ 3939 The Lucky Week (400年一个周期)
- ZOJ-3939 The lucky week
- ZOJ 3939 The Lucky Week (暴力找规律)
- 每日三题-Day6-B(ZOJ 3939 The Lucky Week 找寻环节打表)
- ZOJ 3939 The Lucky Week 2016省赛
- ZOJ 3939 The Lucky Week
- ZOJ3939 The Lucky Week
- ZOJ-3939-The Lucky Week(日期循环节)
- ZOJ 3939 The Lucky Week
- ZOJ-3939 The Lucky Week
- ZOJ 3939 The Lucky Week (打表预处理/找规律)
- zoj 3939 The Lucky Week(打表找循环节)
- ZOJ-3939-The Lucky Week【13th浙江省赛】【找规律】
- The 13th Zhejiang Provincial Collegiate Programming Contest D The Lucky Week
- ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)
- zoj3939 The Lucky Week 找规律
- The Lucky Week
- 【ZOJ3939 The 13th Zhejiang Provincial Collegiate Programming ContestD】【日期前缀和预处理】The Lucky Week 第n个幸运
- D The Lucky Week
- Book of the Week: NINETEEN EIGHTY-FOUR by George Orwell铪铪