• A AD 2020(前缀和,空间压缩,模拟,3维数组)


    2020 is the current year and is a leap year starting on Wednesday of the Gregorian calendar, the 2020th year of the Common Era (CE) and Anno Domini (AD) designations, the 20th year of the 3rd millennium, the 20th year of the 21st century, and the 1st year of the 2020s decade.
    
    2020 has been designated as Year of the Nurse and Midwife by the World Health Organization. The United Nations has declared 2020 as the International Year of Plant Health. 2020 has been designated as International Year of Sound by the International Commission for Acoustics.
    
    Because there are so many unforgettable things happening in 2020, somebody has now proposed that all dates with a substring containing "202" to be designated as the Day for Disaster Reduction. We represent a date in the format YYYYMMDD (for example, 21110202), then if 202 is a substring of this date, this day is the Day for Disaster Reduction.
    
    Please write a program to compute how many Days for Disaster Reduction are there in all the dates between Y_1Y 
    1
    ​
     M_1M 
    1
    ​
     D_1D 
    1
    ​
      and Y_2Y 
    2
    ​
     M_2M 
    2
    ​
     D_2D 
    2
    ​
      (both inclusive)? Note that you should take leap years into consideration. A leap year is a year that can be divided by 400 or can be divided by 4 but can't be divided by 100. A leap year has 2929 days in February, instead of the normal 2828 days.
    
    Input
    The input contains multiple cases. The first line of the input contains a single positive integer TT (1 \le T \le 10^51≤T≤10 
    5
     ), the number of cases.
    
    The first and only line of each case contains six integers Y_1,M_1,D_1,Y_2,M_2,D_2Y 
    1
    ​
     ,M 
    1
    ​
     ,D 
    1
    ​
     ,Y 
    2
    ​
     ,M 
    2
    ​
     ,D 
    2
    ​
     , which are described in the problem statement above.
    
    It's guaranteed that Y_1Y 
    1
    ​
     M_1M 
    1
    ​
     D_1D 
    1is not larger than Y_2Y 
    2
    ​
     M_2M 
    2
    ​
     D_2D 
    2
    ​
     . Both Y_1Y 
    1
    ​
     M_1M 
    1
    ​
     D_1D 
    1
    ​
      and Y_2Y 
    2
    ​
     M_2M 
    2
    ​
     D_2D 
    2
    ​
      are between 20000101 and 99991231, and both dates are valid.
    
    We kindly remind you that the size of the input and output of this problem can be large, so it's recommended to use a faster I/O method. For example, in C++, you can use scanf/printf instead of cin/cout.
    
    Output
    For each case, print a single line containing a single integer, the answer.
    
    Sample 1
    Inputcopy    Outputcopy
    3
    2111 02 01 2111 02 03
    2202 01 01 2202 12 31
    2000 01 01 9999 12 31
    1
    365
    44294
    Note
    In the first sample case, 21110202 is the only Day for Disaster Reduction.
    
    In the second sample case, 202 is a substring of 2202, so every day in the year 2202 is the Day for Disaster Reduction!
    View Problem

     这道题 很自然就想到前缀后,但是发现直接开数组太大,于是

    • 空间压缩,每隔着100,个记录一次前缀后,不足100的在模拟
    • 直接用3维DP去做,因为直接开浪费了很多空间,
  • 相关阅读:
    58. 最后一个单词的长度
    53. 最大子序和
    50. Pow(x, n)
    35. 搜索插入位置
    28. 实现 strStr()
    leetcode 27. 移除元素
    leetcode 26. 删除排序数组中的重复项
    leetcode 21. 合并两个有序链表
    20. 有效的括号
    多线程案例_循环打印_设计4个线程...
  • 原文地址:https://www.cnblogs.com/Lamboofhome/p/16005639.html
Copyright © 2020-2023  润新知