题目链接

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. AC日记——联合权值 洛谷 P1351

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  2. Codeforces Gym101572 B.Best Relay Team (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))

    2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 今日份的训练,题目难度4颗星,心态被打崩了,会的算法太少了,知 ...

  3. DNA的分子结构

    DNA是由两条链组成的, 这两条链按反相平行的方式盘旋成双螺旋结构 DNA分子中的脱氧核糖和磷酸交替连接, 排列在外侧, 构成基本骨架; 碱基排列在内侧. 两条链上的碱基通过氢键连接成碱基对, 并且其 ...

  4. Ubuntu 16.04安装Wine版的迅雷+QQ(完美方案,终极解决方法)

    安装前先备份好系统! 继上一篇安装QQ的方法http://www.cnblogs.com/EasonJim/p/7425978.html,这一篇的QQ采用的是Wine模式安装.完美解决消息记录中文乱码 ...

  5. 卸载ArcGISDesktop低版本程序遇到异常,如何完全卸载?

    [解决办法]:正常情况下,运行 ArcGIS for Desktop 光盘中的 “冲突检测”工具,会自动完全卸载低版本的ArcGIS 程序.如果遇到异常无法卸载(例如安装过非正式版软件),如下位置是A ...

  6. layer的alert、prompt等操作如何响应键盘的回车和ESC操作

    layer.prompt({title: '请输入数据', formType: 1, //隐藏用户输入内容 // 这个是确定按钮的事件 "success":function(){ ...

  7. 关于查看python的trace的方法

    lptrace本质上是基于GDB的,进入到进程内存空间,然后执行了一段python指令把当时的trace给print出来 使用工具:https://github.com/khamidou/lptrac ...

  8. redis cmd 使用样例

    Redis 命令參考 一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15 ...

  9. 计算机的一些经典书籍CS经典书单

    c++: <c++程序设计> <c++primer> <effective c++> <more effective c++> <深入探索c++对 ...

  10. MySQL数据导入与导出

    http://blog.chinaunix.net/uid-23354495-id-3188029.html     mysql备份脚本之select into outfile