poj 3286 How many 0's?

How many 0's?
Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

[Submit]   [Go Back]   [Status]

Description

A Benedict monk No.16 writes down the decimal representations of all natural numbers between and including m and nm ≤ n. How many 0's will he write down?

Input

Input consists of a sequence of lines. Each line contains two unsigned 32-bit integers m and nm ≤ n. The last line of input has the value of m negative and this line should not be processed.

Output

For each line of input print one line of output with one integer number giving the number of 0's written down by the monk.

Sample Input

10 11
100 200
0 500
1234567890 2345678901
0 4294967295
-1 -1

Sample Output

1
22
92
987654304
3825876150

[Submit]   [Go Back]   [Status]

呵呵基本和上一个题一样。。不过只求m——n之间所有数的0的个数

简单。。

排列组合,区间计数,计数序列,二分法,稳定婚姻问题,母函数

Source Code

Problem: E   User: sdau_09_zys
Memory: 164 KB   Time: 110 MS
Language: C++   Result: Accepted
Public:  

#include <iostream>
#include <string>
using namespace std;

__int64 a,b;
__int64 ansa[10],ansb[10];

void count_digits(__int64 s,__int64 ans[],__int64 times=1)//求1-s之间的所有数中 0的个数,1的个数,2.....其中ans[0...9]为返回值
{
    __int64 i,d,p;
    if (s <= 0)return ;
    d = s % 10;
    p = s / 10;
    for (i = 1;i <= d;i ++)ans[i] += times;
    while(p > 0)
    {
        ans[p % 10] += (d + 1) * times;
        p = p / 10;
    }

    for (i = 0;i <= 9;i ++)ans[i] += times * (s / 10);

    times *= 10;
    count_digits((s / 10)-1,ans,times);
    return ;
}


int main()
{
    //int i,j;
    bool is;
while(scanf("%I64d%I64d",&a,&b) != EOF)
{
   if(a==-1&&b==-1)break;
   if(!a&&!b){printf("1\n");continue;}
   is=false;
   memset(ansb,0,sizeof(ansb));
   memset(ansa,0,sizeof(ansa));
   if (a > b)
   {
      swap(a,b);
   }
   //if(a==b)is=true;
   if(a==0)is=true;
   if(a>0)a --;
   if (b > a)
   {
      count_digits(b,ansb);
      count_digits(a,ansa);
   }
   if(is)ansb[0]+=1;
   //if(is)printf("%I64d\n",2*(ansb[0]-ansa[0]));else
    printf("%I64d\n",ansb[0]-ansa[0]);

}

return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值