ZOJ 2392 The Counting Problem(模拟)

时间:2023-01-26 07:47:47

题目链接: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&comma; 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 求&lbrack;a&comma;b&rsqb;或者&lbrack;b&comma;a&rsqb;区间内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&comma; March 2018 Problem F,发现循环节 &plus; 线段树 &plus; 永久标记)

    题目链接  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&sol;zoj 2615 Cells(栈模拟dfs)

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

  9. hdu&lowbar;5832&lowbar;A water problem&lpar;模拟&rpar;

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

随机推荐

  1. MacOS平台下&commat;rpath在动态链接库中的应用

    一.背景介绍 公司开发的一个底层库被用在了Mac平台的多个产品中.在开发这个底层库的初期,对于Mac OSX下的Install name 并没有过多的了解.对于XCode中的install name项 ...

  2. 1-1 gulp 实战

    npm install gulp-htmlmin gulp-imagemin imagemin-pngcrush gulp-minify-css gulp-jshint gulp-uglify gul ...

  3. Linux 下如何使用看门狗

      Linux内核有集成WD的选项.将其使能后,系统里就会有watchdog的设备驱动:/dev/watchdog.这样,在应用程序里只需打开这个设备使用即可:#include <fcntl.h ...

  4. Dev环境中的集成测试用例执行时上下文环境检查(实战)

    Dev环境中的集成测试用例执行时上下文环境检查(实战) Microsoft.NET 解决方案,项目开发必知必会. 从这篇文章开始我将分享一系列我认为在实际工作中很有必要的一些.NET项目开发的核心技术 ...

  5. hdu&lowbar;1042&lpar;模拟大数乘法&rpar;

    计算n! #include<cstring> #include<cstdio> using namespace std; ]; int main() { int n; whil ...

  6. GitHub上README&period;md的简单介绍

    1.编辑README文件 大标题(一级标题):在文本下面加等于号,那么上方的文字就变成了大标题,等于号的个数无限制,但一定要大于0 大标题 ==== 中标题(二级标题):在文本下面加下划线,那么上方的 ...

  7. hdu4533 线段树维护分段函数

    更新:x1,y1,x2,y2不用long long 会wa.. #include<iostream> #include<cstring> #include<cstdio& ...

  8. 写在vue总结之前&lpar;一&rpar;

    在大概2016年6月吧,知道了vue,博客园有个博主用vue写了一个不算完整的博客园app,做出来的效果相比博客园原本的app看上去要华丽很多,那时候做前端还没多久,很多东西都不知道,别人说用vue开 ...

  9. L2tp协议简单解析

    1.L2TP简介 L2TP(Layer 2 Tunneling Protocol,二层隧道协议)是VPDN(Virtual PrivateDial-up Network,虚拟私有拨号网)隧道协议的一种 ...

  10. MyEclipse中使用Junit插件进行单元测试

    http://wenku.baidu.com/view/ec904a116bd97f192279e9a6.html