ZOJ - 3950 How Many Nines 【前缀和】
题目链接
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 【前缀和】的更多相关文章
- zoj 3950 how many nines
https://vjudge.net/problem/ZOJ-3950 题意: 给出两个日期,计算从第一个日期开始到第二个日期,每一天的日期中的9加起来一共有多少个. 思路: 看题解补的题.首先看这题 ...
- 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 ...
- ZOJ How Many Nines 模拟 | 打表
How Many Nines Time Limit: 1 Second Memory Limit: 65536 KB If we represent a date in the format ...
- 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 ...
- ZOJ 4029 - Now Loading!!! - [前缀和+二分]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4029 Time Limit: 1 Second Memory L ...
- ZOJ 刷题记录 (。・ω・)ノ゙(Progress:31/50)
[热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ...
- 高级数据结构(树状数组套主席树):ZOJ 2112 Dynamic Rankings
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- 主席树[可持久化线段树](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 ...
- ZOJ Monthly, March 2018 题解
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...
随机推荐
- LeetCode OJ--Unique Paths *
https://oj.leetcode.com/problems/unique-paths/ 首先,转换成一个排列组合问题,计算组合数C(m+n-2) (m-1),请自动想象成上下标. class S ...
- tableView刷新中的问题
在开始之前先上一张效果图 相信大家都看到了“店铺优惠”这一栏,在这里假设这一栏就是单独的一个cell,当无店铺优惠的时候不可点击在有店铺优惠的时候会弹出优惠列表,选中并返回时会刷新数据,所以弹出视图采 ...
- HDU 1045 Fire Net 状压暴力
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- highcharts中放aqi及6要素,再加上气象5要素的图
var chart = Highcharts.chart('container', { chart: { zoomType: 'xy' }, title: { text: '东京月平均天气数据' }, ...
- 细说Redis持久化机制
概述 Redis不仅能够作为缓存来使用,也能够作为内存数据库. Redis作为内存数据库使用时.必需要解决一个问题:数据的持久性.有些将Redis作为缓存使用的场景也需要将缓存的数据持久化到存储介质上 ...
- CD_Lulu软件著作权中软件分类号
计算机软件著作权 登记中使用的软件分类编码指南 一.计算机软件著作权登记中使用的软件分类编码的结构采用组合代码结构,由9位数字组成并按照从左至右的顺序排列,前5位数字代表计算机软件分的代码:后4位数字 ...
- poj-3744-Scout YYF I-矩阵乘法
f[i]=f[i-1]*p+f[i-2]*(1-p); 正好能够用矩阵加速. . . . #include<stdio.h> #include<string.h> #inclu ...
- ubuntu 卸载干净软件(包括配置文件)
var/cache/apt/archives occupying huge space I am in the process of cleaning up my system. And I see ...
- Appium 从 0 到 1 搭建移动 App 功能自动化测试平台 (1):模拟器中运行 iOS 应用
转载:https://testerhome.com/topics/4960 在上一篇文章中,我对本系列教程的项目背景进行了介绍,并对自动化测试平台的建设进行了规划. 在本文中,我将在已准备就绪的iOS ...
- VUE高仿饿了么app开发思维导图
来自互联网 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing