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-D2are 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++.

<h4< dd="">Output

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

<h4< dd="">Sample Input

4
2017 04 09 2017 05 09
2100 02 01 2100 03 01
9996 02 01 9996 03 01
2000 01 01 9999 12 31

<h4< dd="">Sample Output

4
2
93
1763534

<h4< dd="">Hint

For the first test case, four 9s appear in all the dates between 2017-04-09 and 2017-05-09. They are: 2017-04-09 (one 9), 2017-04-19 (one 9), 2017-04-29 (one 9), and 2017-05-09 (one 9).

For the second test case, as year 2100 is not a leap year, only two 9s appear in all the dates between 2100-02-01 and 2100-03-01. They are: 2017-02-09 (one 9) and 2017-02-19 (one 9).

For the third test case, at least three 9s appear in each date between 9996-02-01 and 9996-03-01. Also, there are three additional nines, namely 9996-02-09 (one 9), 9996-02-19 (one 9) and 9996-02-29 (one 9). So the answer is 3 × 30 + 3 = 93.

这题一开始打算暴力模拟过去 结果写着写着不对劲了

后面扔给专门写模拟的队友写了

暴力打表过的

这样好写多了

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 1e6 + ;
int a[] = {, , , , , , , , , , , };
int check(int x) {
if ((x % ) == || (x % == && x % != )) return ;
return ;
}
int get9(int x) {
int ans = ;
while(x) {
int cnt = x % ;
if (cnt == ) ans++;
x /= ;
}
return ans;
}
int ans[][][];
int main() {
int year = , yue = , day = , cnt = , ret;
while(year < ) {
yue = ;
while(yue <= ) {
day = ;
if (yue == && check(year)) ret = a[yue - ] + ;
else ret = a[yue - ];
while(day <= ret ) {
int temp = get9(year) + get9(yue) + get9(day);
ans[year][yue][day] = cnt + temp;
cnt = ans[year][yue][day];
day++;
}
yue++;
}
year++;
}
int n, v1, m1, d1, v2, m2, d2;
sf(n);
for (int i = ; i < n ; i++) {
sfff(v1, m1, d1);
sfff(v2, m2, d2);
printf("%d\n", ans[v2][m2][d2] - ans[v1][m1][d1] + get9(v1) + get9(m1) + get9(d1));
}
return ;
}

How Many Nines ZOJ - 3950 打表大法好的更多相关文章

  1. ZOJ - 3950 How Many Nines 【前缀和】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3950 题意 给出两个日期 求 这个日期 经过 到 另外一个日期 ...

  2. zoj 3950 how many nines

    https://vjudge.net/problem/ZOJ-3950 题意: 给出两个日期,计算从第一个日期开始到第二个日期,每一天的日期中的9加起来一共有多少个. 思路: 看题解补的题.首先看这题 ...

  3. HDU 6063 17多校3 RXD and math(暴力打表题)

    Problem Description RXD is a good mathematician.One day he wants to calculate: ∑i=1nkμ2(i)×⌊nki−−−√⌋ ...

  4. 【P1379】天才的约数和

    来自GDOI2007,原题已不可考-- 又自己做出来了好开心,找特殊性是个关键的切入点 原题: 这天周航遇到了靳泽旭. 周航:"我是天才!" 靳泽旭:"你为什么是天才?& ...

  5. 【BZOJ 4547】【HDU 5157】小奇的集合

    http://www.lydsy.com/JudgeOnline/problem.php?id=4547 本蒟蒻并不会矩乘求Fibonacci数列前缀和,所以果断分块打表,常数竟然比矩乘要小! PS: ...

  6. BZOJ3057 圣主的考验

    Poetize11的T3 DP神优化= =反正蒟蒻不会 Orz ZYF竟然找到了题解,反正我是没找到T T(百度空间:你太沙茶了,不给你看题解2333) 然后就对着标程写了一遍,然后T了...233 ...

  7. 二模 (9) day2

    第一题: 题目大意:求满足条件P的N位二进制数的个数.P:该二进制数有至少3个0或者3个1挨在一起.. N<=20000 解题过程: 1.一开始直接写了个dfs把表打了出来,不过没发现什么规律, ...

  8. weapon制作武器

    weapon制作武器 (weapon.pas/c/cpp) 解题报告 制作武器weapon.pas/c/cpp) 背景 WZland的紧急避难所很快就建好了,WZland的居民们陆续地来到这个紧急避难 ...

  9. poj2739尺取法+素数筛

    Some positive integers can be represented by a sum of one or more consecutive prime numbers. How man ...

随机推荐

  1. 389. Valid Sudoku【LintCode java】

    Description Determine whether a Sudoku is valid. The Sudoku board could be partially filled, where e ...

  2. Executor Framework

    Why? look at the following 2 pieces of code for implementing a simple web server based on socket, ca ...

  3. 基于Kubernetes(k8s)网络方案演进

    VIP PaaS在接近两年时间里,基于kubernetes主要经历四次网络方案的变迁: 1. kubernetes + flannel 2. 基于Docker libnetwork的网络定制 3. k ...

  4. 欢迎来怼——第14次Scrum会议(10/26)

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/26  17:00~17:13(总计13min).地点:计 ...

  5. Scrum1

    Scrum1 组员 任务分工 贡献 林泽宇 团队分工.撰写博客.修改完善需求规格说明书.整理代码规范 李涵 后端架构设计 尹海川 logo设计修改.数据库数据 郏敏杰 课堂展示.查阅资料.整理关键和难 ...

  6. Android中Parcelabel对象的使用和理解

    1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...

  7. TCP系列10—连接管理—9、syncookie、fastopen与backlog

    这部分内容涉及较多linux实现,可以跳过. 一.listen系统调用对backlog的处理 当socket处于LISTEN或者CLOSED状态时,fastopen队列的长度可以通过TCP_FASTO ...

  8. Ligerui首页的快速搭建

    一.目录 1.多层架构+MVC+EF+AUTOFAC+AUTOMAPPER: 2.MVC中验证码的实现(经常用,记录备用) 3.Ligerui首页的快速搭建 4.Ligerui Grid组件--学生信 ...

  9. java面试95题

    1.面向对象的特征有哪些方面? 答:面向对象的特征主要有以下几个方面: - 抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象和行为抽象两方面.抽象只关注对象有哪些属性和行为,并不关注 ...

  10. 【Docker 命令】- pause/unpause 命令

    docker pause :暂停容器中所有的进程. docker unpause:恢复容器中所有的进程. 语法 docker pause [OPTIONS] CONTAINER [CONTAINER. ...