题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1368

题目大意:计算从S到T中所有的数,其中0,1,2,3,4,5,6,7,8,9的个数,例如从1024到1032有1024 1025 1026 1027 1028 1029 1030 1031 1032,其中10个0,10个1,7个2,3个3等等

Sample Input

1 10
44 497
346 542
1199 1748
1496 1403
1004 503
1714 190
1317 854
1976 494
1001 1960
0 0

Sample Output

1 2 1 1 1 1 1 1 1 1
85 185 185 185 190 96 96 96 95 93
40 40 40 93 136 82 40 40 40 40
115 666 215 215 214 205 205 154 105 106
16 113 19 20 114 20 20 19 19 16
107 105 100 101 101 197 200 200 200 200
413 1133 503 503 503 502 502 417 402 412
196 512 186 104 87 93 97 97 142 196
398 1375 398 398 405 499 499 495 488 471
294 1256 296 296 296 296 287 286 286 247

代码如下:

 # include<iostream>
# include<cstdio>
# include<cstring>
# include<algorithm>
# include<vector>
using namespace std; int s,t;
int res[],dig[],len; void solve(int num)
{
num ++;
len =;
int temp =;
while()
{
dig[++len] = num%;
num /= ;
if(!num) break;
temp *= ;
}
for(int i=; i<; i++) res[i] += (len-)*temp/;
res[] += (len-)*temp/-(temp-)/;
for(int i=; i<dig[len]; i++)
{
res[i] += temp;
for(int j=; j<; j++)
res[j] += (len-)*temp/;
}
temp /= ;
for(int i=len-; i>=; i--)
{
for(int j=; j<dig[i]; j++)
{
for(int k=len; k>i; k--)
res[dig[k]] += temp;
res[j] += temp;
for(int k=; k<; k++)
res[k] += (i-)*temp/;
}
temp /= ;
}
} int main()
{
while(scanf("%d%d",&s,&t)&& s &&t)
{
memset(res,,sizeof(res));
if(s>t) swap(s,t);
solve(s-);
for(int i=; i<; i++)
res[i] = -res[i];
solve(t);
for(int i=; i<; i++)
printf("%d ",res[i]);
printf("%d\n",res[]);
}
return ;
}

ZOJ 2392 The Counting Problem(模拟)的更多相关文章

  1. ZOJ 3326 An Awful Problem 模拟

    只有在 Month 和 Day 都为素数的时候才能得到糖 那就模拟一遍时间即可. //#pragma comment(linker, "/STACK:16777216") //fo ...

  2. POJ2282 The Counting Problem

    题意 Language:DefaultEspañol The Counting Problem Time Limit: 3000MS Memory Limit: 65536K Total Submis ...

  3. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  4. UVA 1640 The Counting Problem UVA1640 求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数。

    /** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a] ...

  5. ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)

    题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...

  6. 『The Counting Problem 数位dp』

    The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结 ...

  7. The Counting Problem

    The Counting Problem 询问区间\([a,b]\)中\(1\sim 9\)出现的次数,0 < a, b < 100000000. 解 显然为数位递推,考虑试填法,现在关键 ...

  8. UVALive 3486/zoj 2615 Cells(栈模拟dfs)

    这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...

  9. hdu_5832_A water problem(模拟)

    题目链接:hdu_5832_A water problem 这是一个惨痛的教训,想这种这么大的大数肯定就是找个规律模拟一下. 然而我们队还写JAVA,用大数艹了13发罚时,真是TM智障了. #incl ...

随机推荐

  1. 教你50招提升ASP.NET性能(五):确保分页是在数据层完成的

    (11)Make sure paging is conducted at the database layer 招数11: 确保分页是在数据层完成的 When using grid UI contro ...

  2. ThinkPHP3.2.3新特性之:数据库设置

    ThinkPHP3.2.3版本数据库驱动采用PDO完全重写,配置和使用上面也比之前版本更加灵活和强大,我们来了解下如何使用. 首先,3.2.3的数据库配置信息有所调整,完整的数据库设置包括: /* 数 ...

  3. HDU 5481 Desiderium 动态规划

    Desiderium Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=548 ...

  4. delphi 连接mysql

    Delphi连接MySQL真麻烦,研究了一天,从网上找了无数文章,下载了无数插件都没解决.最后返璞归真,老老实实用ADO来连接,发现也不是很顺利,但最终还是连接成功了.多少有点心得:ADO各个组件的作 ...

  5. iOS开发——高级技术&摇一摇功能的实现

    摇一摇功能的实现 在AppStore中多样化功能越来越多的被使用了,所以今天就开始介绍一些iOS开发的比较实用,但是我们接触的比较少的功能,我们先从摇一摇功能开始 在 UIResponder中存在这么 ...

  6. solr-1.4.1 环境配置

    solr-1.4.1 环境配置: Solr是一个apache名下非常好用的开源索引.搜索工具,网上的资料虽多但非常杂,笔者花了一天的时间对Solr进行了较为初步的研究,对Solr的基础应用做了一定的总 ...

  7. php中用户自定义排序

    php中数组用户自定义排序函数有usort和uasort,前者键值重新排列,后者保持原数组的键值. 举例usrot: usort($filterArr, 'sortArr'); function so ...

  8. WebStorm 6.0下运行pomelo项目

    最近想使用WebStorm来写pomelo,初次使用WebStorm,网上找了老半天根本没有介绍WebStorm如何创建或者打开运行pomelo的教程,网易pomelo官网介绍的使用 WebStorm ...

  9. android开发之路01

    一.android系统被分为4个层次:1.最下层的是linux核心,包括多个驱动程序,提供了操作系统应该具备的核心功能:2.在linux核心之上,包括两个部分,一部分是Android Runtime( ...

  10. Android_Intent_passValue(4)

    xml布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...