码迷,mamicode.com
首页 > 其他好文 > 详细

[省赛训练]How many nines

时间:2020-04-05 22:01:51      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:describe   多少   instead   line   amp   end   test   来讲   printf   

题面:

If we represent a date in the format YYYY-MM-DD (for example, 2017-04-09), do you know how many 9s will appear in all the dates between Y1-M1-D1 and Y2-M2-D2 (both inclusive)?

Note that you should take leap years into consideration. A leap year is a year which can be divided by 400 or can be divided by 4 but can‘t be divided by 100.

Input

The first line of the input is an integer T (1 ≤ T ≤ 105), indicating the number of test cases. Then T test cases follow. For each test case:

The first and only line contains six integers Y1M1D1Y2M2D2, their meanings are described above.

It‘s guaranteed that Y1-M1-D1 is not larger than Y2-M2-D2. Both Y1-M1-D1 and Y2-M2-D2 are between 2000-01-01 and 9999-12-31, and both dates are valid.

We kindly remind you that this problem contains large I/O file, so it‘s recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.

Output

For each test case, you should output one line containing one integer, indicating the answer of this test case.

 

嘛,实际上是一道比较简单的模拟题……

题意就是给两个日期 年月日 求两个日期间一共有多少9

 

 

思路就是 先预处理一下大数组nine[10000][13][32]

定义数组里的值:从2000-01-01 到 nowyear-nowmonth-nowday的9的数目

求9的数目 就是/10 %10 一位位的看就好

初始化好数组之后直接O(1)查就好

Owo 前缀和! 就是那种 跟数组区间有关系的问题

用前缀和来讲是比较方便的=-=

 

[省赛训练]How many nines

标签:describe   多少   instead   line   amp   end   test   来讲   printf   

原文地址:https://www.cnblogs.com/leafsblogowo/p/12639294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!