The first solution to find the law
1. Ideas
- Figure is eleven symmetrical relationship should be noted hereThe year is divided into two halves
- " Day " is the most middle of the order of symmetry can only be 11 or 22 these two kinds of situations
int ri[2]={11,22};
- Then analyzes the " Month - " this right, for the month to meet from 1 to 12, the time to meet the 0 to 23
so that only the following five kinds of situations:
when May
01-10
02-20
11-11
12-21
13-31
int yue[5]={1,2,10,11,12};
-
Next Analysis " annual - points , 'which, year after satisfying 0 to 99, 0 to 59 minutes to meet; seen from the range, for all the points have respective corresponding year after, so a total of 60 kinds of cases
Only values recited herein year after, the value of its symmetric sub
int hyear[60]={0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23,24,25,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,53,54,55,60,61,62,63,64,65,70,71,72,73,74,75,80,81,82,83,84,85,90,91,92,93,94,95};
- Finally, " Two years ago - s , 'which, in the range of 20 to 90 years ago, is the range of 0 to 59 seconds, a total of 48 kinds of cases
int qyear[48]={20,21,22,23,24,25,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,53,54,55,60,61,62,63,64,65,70,71,72,73,74,75,80,81,82,83,84,85,90,91,92,93,94,95};
So then, is clear stroked scheduling problems
we usually change the seconds, then changed. . .
But because it is symmetrical around as long as the change in hours, minutes, seconds, month, year after year before will change accordingly! ! ! , The second change, in fact, also changed the year. The order is not right.
So just look like the first half, change the order is
D -> -> the year after -> the previous year.
2.AC Code
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int qyear[48]={20,21,22,23,24,25,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,53,54,55,60,61,62,63,64,65,70,71,72,73,74,75,80,81,82,83,84,85,90,91,92,93,94,95};
int hyear[60]={0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23,24,25,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,53,54,55,60,61,62,63,64,65,70,71,72,73,74,75,80,81,82,83,84,85,90,91,92,93,94,95};
int yue[5]={1,2,10,11,12};
int ri[2]={11,22};
int main()
{
int a,b,c,d,k,qy,hy,y,r,s,f,m;
cin>>k;
k=k+122;///初始时间为2000 01 11 10 00 02(各数组的第一个数),那么题目给的开始时间是第122个。
a=(k-1)/600;///600是由2*5*60得来的,即一个前年(qyear)共对应600种情况,第六百个还属于qyear【0】,(k-1)是为了避免将它划分到qyear【1】中。
qy=qyear[a];
k=k-a*600;
//cout<<a<<endl;
if(k==0){m=qy/10+(qy%10)*10;printf("%02d6012222106%02d",qy,m);return 0;}///如果减完之后,k=0,那么他就是这一组的最后一种情况,如输出。
b=(k-1)/10;///10由2(日)*5(月)得来,一个后年共对应10种情况。
hy=hyear[b];
k=k-b*10;
//cout<<b<<endl;
if(k==0){m=qy/10+(qy%10)*10;f=hy/10+(hy%10)*10;printf("%02d%02d122221%02d%02d",qy,hy,f,m);return 0;}
c=(k-1)/2;
//cout<<c<<endl;
y=yue[c];
k=k-c*2;
m=qy/10+(qy%10)*10;f=hy/10+(hy%10)*10;s=y/10+(y%10)*10;
if(k==2){printf("%02d%02d%02d22%02d%02d%02d",qy,hy,y,s,f,m);return 0;}
///%02d 会自动补零
else{printf("%02d%02d%02d11%02d%02d%02d",qy,hy,y,s,f,m);return 0;}
}
The second solution for cycling, structure
1. Ideas
A preliminary analysis of the same solution
- Each data storage structure
struct ans
{
int year;
int month;
int date;
int hour;
int minute;
int second;
}f[30000];
- loop has been circulating for years from 2020 to 9999
give the values in minutes and seconds, is determined whether the conditions, i.e. 0 to 59 belong to - If you meet the conditions, then this year there will be 10 kinds of cases (two kinds of date * 5 Zhong month)
- Structure is then stored in array
2.AC Code
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int month[6] = {0,1,2,10,11,12};
int date[3] = {0,11,22};
struct ans
{
int year;
int month;
int date;
int hour;
int minute;
int second;
}f[30000];
int main()
{
int k;
cin >> k;
int t=1;
for(int i = 2020; i <= 9999; i ++)
{
int a = i;
int b = a % 100;
int minute = (b%10) * 10 + (b/10);
if(minute >= 0 && minute <= 59)
{
int c = a / 100;
int second = (c%10) * 10 + (c/10);
if(second >= 0 && second <= 59)
{
for(int p=1;p<=5;p++)///月
{
for(int w=1;w<=2;w++)///日
{
f[t].year=a;
f[t].month=month[p];
f[t].date=date[w];
f[t].hour=f[t].month/10+(f[t].month%10)*10;
f[t].minute=minute;
f[t].second=second;
t++;
}
}
}
}
}
int m=k+2;///题目给的时间,是数组中的第二个
printf("%d%02d%02d%02d%02d%02d",f[m].year,f[m].month,f[m].date,f[m].hour,f[m].minute,f[m].second);
return 0;
}