UVA 11038

來源:互聯網
上載者:User

傳送門:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=470&problem=1979

 

題意:求[m,n]中有多少個0

題解:分位元分析:
n的第i位不為0=n左邊的數(高位)*10^(i-1)
n的第i位為0 =(n左邊的數-1)*10^(i-1)+(i位右邊的數+1)
ans=f(n)-f(m-1);

注意m為0的情況即可。

 

AC代碼:

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s)  scanf("%s",s)#define pi1(a)    printf("%d\n",a)#define pi2(a,b)  printf("%d %d\n",a,b)#define mset(a,b)   memset(a,b,sizeof(a))#define forb(i,a,b)   for(int i=a;i<b;i++)#define ford(i,a,b)   for(int i=a;i<=b;i++)typedef long long LL;const int N=110001;const int M=1000007;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;LL xiaohao(LL l){    LL sum=0,j=1,r=0,m;    while(l)    {        m=l%10;        l/=10;        if(m)   sum+=l*j;        else    sum+=(l-1)*j+r+1;        r=r+m*j;        j=j*10;    }    return sum;}int main(){    LL n,m;    while(scanf("%lld%lld",&m,&n)&&m>=0)    {        LL x=xiaohao(n)-xiaohao(m-1);        if(m==0)    x++;        printf("%lld\n",x);    }    return 0;}


 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.