题目链接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3950

题意

给出两个日期

求 这个日期 经过 到 另外一个日期 这中间经过的日期 (包括两个端点) 中 有多少个9

思路

刚开始 想模拟 然后 测试数据 达到 1e5 然后 T掉了

可能是 模拟写的 不够优吧

后来 想到用 前缀和

但是 一个 日子

99991231 如果 开 一维数组 保存的话 会MLE

然后 想到用 三维数组

就可以了

AC代码

#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <deque>
#include <queue>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define pb push_back
#define CLR(a) memset(a, 0, sizeof(a)) using namespace std;
typedef long long ll;
typedef unsigned long long ull; const int INf = 0x3f3f3f3f;
const int maxn = 1e4 + 5;
const int year = 0; int leap[maxn];
int coun[maxn];
ll ans[maxn][15][35]; bool isleap(int x)
{
if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0)
return true;
return false;
} int tran(int x)
{
int ans = 0;
while (x)
{
if (x % 10 == 9)
ans++;
x /= 10;
}
return ans;
} void init()
{
int tot[2][13] =
{
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
CLR(leap);
CLR(ans);
for (int i = 2000; i <= 9999; i++)
{
if (isleap(i))
leap[i] = 1;
coun[i] = tran(i);
}
ll vis = 0;
for (int i = 2000, j = 1, k = 1; ; )
{
ans[i][j][k] = vis + coun[i] + tran(j) + tran(k);
vis = ans[i][j][k];
k++;
if (tot[leap[i]][j] == k - 1)
{
j++;
k = 1;
}
if (j == 13)
{
i++;
j = 1;
}
if (i == 10000)
break;
}
} int main()
{
init();
int t;
scanf("%d", &t);
while (t--)
{
int a, b, c, d, e, f;
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
ll answ = ans[d][e][f] - ans[a][b][c];
answ += tran(a) + tran(b) + tran(c);
printf("%lld\n", answ);
}
}

ZOJ - 3950 How Many Nines 【前缀和】的更多相关文章

  1. zoj 3950 how many nines

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

  2. How Many Nines ZOJ - 3950 打表大法好

    If we represent a date in the format YYYY-MM-DD (for example, 2017-04-09), do you know how many 9s w ...

  3. ZOJ How Many Nines 模拟 | 打表

    How Many Nines Time Limit: 1 Second      Memory Limit: 65536 KB If we represent a date in the format ...

  4. ZOJ 17届校赛 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 w ...

  5. ZOJ 4029 - Now Loading!!! - [前缀和+二分]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4029 Time Limit: 1 Second Memory L ...

  6. ZOJ 刷题记录 (。・ω・)ノ゙(Progress:31/50)

    [热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ...

  7. 高级数据结构(树状数组套主席树):ZOJ 2112 Dynamic Rankings

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  8. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )

    在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...

  9. ZOJ Monthly, March 2018 题解

    [题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...

随机推荐

  1. jQuery 1.4版本的15个新功能(现在已经发布到jquery1.8,特别是增强版的live事件,支持 submit , change , focus 和 blur 事件)

    1.jQuery()创建DOM元素:支持传参设置属性 之前,jQuery可以通过 attr 方法设置元素的属性,既可传属性的名和值,也可以是包含几组特定 属性名值对 的 对象.在 jQuery 1.4 ...

  2. Python通用编程

    本文是Python通用编程系列教程,已全部更新完成,实现的目标是从零基础开始到精通Python编程语言.本教程不是对Python的内容进行泛泛而谈,而是精细化,深入化的讲解,共5个阶段,25章内容.所 ...

  3. 基于python脚本的对拍debug

    首先,这是python脚本 import os; for i in range(0,20): print ("Case:"+str(i)); print ("random ...

  4. deferred 对象

    转载,原文连接:http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html ...

  5. CUDA 实现JPEG图像解码为RGB数据

    了解JPEG数据格式的人应该easy想到.其对图像以8*8像素块大小进行切割压缩的方法非常好用并行处理的思想来实现.而其实英伟达的CUDA自v5.5開始也提供了JPEG编解码的演示样例.该演示样例存储 ...

  6. git 使用及常用命令

    git在团队项目中的使用流程 1.首先从一个git远程仓库中clone项目到本地 ? 1 git clone 仓库地址 2.创建开发分支 一般我们写代码不会在master分支上面写,而是新建一个分支 ...

  7. hadoop常见错误

    hadoop常见错误集锦: 1.DataXceiver error processing WRITE_BLOCK operation ERROR org.apache.hadoop.hdfs.serv ...

  8. C++ 继承与接口 知识点 小结(一)

    [摘要] 要求理解覆盖.重载.隐藏的概念与相互之间的差别.熟记类继承中对象.函数的訪问控制:掌握虚函数.虚函数表.虚函数指针的联系:理解区分虚函数和虚继承在虚方法.虚指针在空间分配上的重点与难点:熟练 ...

  9. tcp ip协议笔记(1)——简单介绍

    前言 本人记性不佳,看书健忘,以此笔记来记录看书后自己所知所想,已达到加深对tcp ip的理解.本笔记不过我看完书后自己所写的总结,权当是书后复习. 一.为什么会有tcp ip协议        ...

  10. weblogic中部署项目报错org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken .

    原因: 原因是weblogic要查找自己的antlr,和lib下面的antlr包冲突.... 解决方法: 在weblogic.xml添加 <container-descriptor>    ...