[省赛训练]How many nines

Posted leafsblogowo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[省赛训练]How many nines相关的知识,希望对你有一定的参考价值。

题面:

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的主要内容,如果未能解决你的问题,请参考以下文章

ZOJ 17届校赛 How Many Nines

ZOJ 3950 How Many Nines

zoj 3950 how many nines

ZOJ 3950 - How Many Nines

天梯赛和蓝桥杯省赛训练

省赛训练赛(---)