Luo Gu P2010 [date] palindromic solution to a problem

Ideas: Analog, enumerate

This question is NOIP2016 PJ T2, as the second question the popularity of the group, I think it is for the popularity of groups of players who still have some difficulty.

I did not think that an enumeration @ "QQ red envelope" Gangster Administrator day of the $ O (N ^ 2) $ approach, wrote the triple loop, the enumeration date, and then determine whether or not a palindrome. Then it became the worst solution (

The main comments in the code.

$ \rm code $

# include <bits/stdc++.h>
# define ll long long
# define rg register
# define il inline
# define mem(a, num) memset(a, num, sizeof(a))
# define debug(s, x) cout << s << " -> " << x << endl
const bool oj = true;
using namespace std;
template < typename T >
il void readInt(T &x) {
    x = 0; rg T f = 1; rg char ch = getchar();
    while(!isdigit(ch)) f = ch == '-' ? -1 : f, ch = getchar();
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}
template < typename T >
il int Max(T a, T b) {return a > b ? a : b;}
template < typename T >
il int Min(T a, T b) {return a < b ? a : b;}
void file() {
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
}
// ---head file--- //

int date1, date2; //两个日期
int xhw[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //How many days each month, in February due to leap year, it requires special handling. 
IL void Change ( int ); // modification function date February 
IL BOOL orz ( int , int , int ); // determine whether the date is a function of the number of palindromic 
int main () {
     IF (! File (OJ) ); 
    readInt (date1), readInt (that represented by DATE2); 
# define y1 Y1 // because this variable y1 cmath library with something there is a conflict, we first define it here 
    int y1 = date1 / 10000 , y2 = that represented by DATE2 / 10000 , M1 = date1 / 100 % 100 , M2 = DATE2 / 100 % 100// when the enumeration of the month, need to take note. We can try to understand their own look, if there do not understand, I can private letter. Here because the layout and other reasons not elaborate.
    
        
        for ( int H = T1; H <= T2; H ++) { // Enumeration months 
            IF (H == 2 ) change (X); // if February into the change function 
            for ( int W = . 1 ; W <= XHW [H]; W ++) // enumeration day 
                IF (orz (X, H, W)) ANS ++; // if date palindromic, ans accumulation. 
        } 
    } 
    The printf ( " % D " , ans); // final output can ans. 
    return  0 ; 
} 
IL void Change ( int X) { 
    XHW [ 2 ] = (((X%4 == 0 ) && (the X-% 100 ! = 0 )) || (the X-% 400 == 0 ))? 29 : 28 ; // If the year is a leap year, the number of days to February 29, otherwise 28 . 
} 
IL BOOL orz ( int X, int H, int W) {
     int A [ 10 ]; 
    A [ . 1 ] = X / 1000 , A [ 2 ] = X / 100 % 10 , A [ . 3 ] = X / 10 % 10 , A [ . 4] X% = 10 , A [ . 5 ] = H / 10 , A [ . 6 ]% H = 10 , A [ . 7 ] = W / 10 , A [ . 8 ] W% = 10 ;
     // decomposition eight years every daytime 
    IF (a [ . 1 ] == a [ . 8 ] && a [ 2 ] == a [ . 7 ] && a [ . 3 ] == a [ . 6 ] && a [ . 4 ] == a [ . 5 ]) return  to true ; // if the date is a palindrome, returns to true 
    return  false ; // false otherwise
}

 

Reproduced in: https: //www.cnblogs.com/Xray-luogu/p/11006445.html

Guess you like

Origin blog.csdn.net/weixin_34248705/article/details/93306837