zzulioj - 2600: how many days?

Topic links: http://acm.zzuli.edu.cn/problem.php?id=2600

Title Description
Small D students on the issue date of the class is very interested, known 1900-01-01 Monday, so small D would like to know, given two years of x, y, in [x, y] in each year, z monthly number is the number of days how many days of the week w. For example x, y, z, w are 1900,2000,12,7, showing each year between 1900 to 2000 (including 1900 and 2000), 12 month, how many days are seven weeks (Sunday).
Entry
Multiple sets of test data, ending with an EOF.
Each test line, four integers each line, in order, are the x, y, z, w. Where 1900 <= x <= y < = 2100,1 <= z <= 31,1 <= w <= 7.
Export
For each test, an output line, each line an integer, its meaning as described in the title. Note z If the number of the month does not exist, ignore, such as z = 31, February 31 does not exist, can be ignored.
Sample input  Copy
2019 2019 8 7
2010 2019 31 7
Sample output  Copy
2 
10

simulation, since 19,000,101 Monday, adding it would from that day until the title is added to meet the conditions of the zone where then do judgment
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mst(a) memset(a, 0, sizeof(a))
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll ll_INF = 0x3f3f3f3f3f3f3f;
const int maxn = 1e4+10;
const int ls[13] = {0, 31, 28, 31 is , 30 , 31 is , 30 , 31 is , 31 is , 30 , 31 is , 30 , 31 is };
 BOOL ISR ( int Y) { // Analyzing leap year 
    return (% Y 100 && (Y%! . 4 || (Y))! % 400 ); 
} 
BOOL OK ( int SUM, int W) { // judgment is not circumferential W 
    return SUM% . 7 + . 1 == W; 
} 
intmain ( void ) {
     int X, Y, Z, W;
     the while (~ Scanf ( " % D% D% D% D " , & X, & Y, & Z, & W)) { 
        LL SUM = Z- . 1 ; 
         int Start = 1900 ;
         the while (Start <X) { // calculate days z January 1900 to January of 1 x 
            SUM + = ( 365 + ISR (Start));
             ++ Start; 
        } 
        int CNT = 0 ;
         the while (Start <= Y) { // solving answer 
            for ( int= I . 1 ; I <= 12 is ; ++ I) { 
                SUM + LS = [I- . 1 ]; // plus the month days 
                IF (I == . 3 ) // if you want to add the number of days in February , is determined not to make. 1 
                    SUM + = ISR (Start);
                 IF ((I == 2 && Z> LS [ 2 !] + ISR (Start)) || (I = 2 && Z> LS [I])) // If the number does not exist z month, skip, without counting the number of 
                    Continue ; 
                CNT + = OK (SUM, W); // count the number 
            } 
            SUM + LS = [ 12 is]; // plus the number of days of December 
            ++ Start; // change to the year 
        } 
        the printf ( " % D \ n- " , CNT); 
    } 
    return  0 ; 
}

 

 

Guess you like

Origin www.cnblogs.com/shuitiangong/p/12076012.html