zoukankan      html  css  js  c++  java
  • $ [Contest #4]$求和 思博题

    正解:

    解题报告:

    传送门$QwQ$

    一道看起来是数位$dp$其实并不是的题$QwQ$

    首先求$sum_{l}^r$就变成$sum_1^r-sum_1^{l-1}$不说$QwQ$.现在就只要求$sum_{i=1}^n f(n)$了$QwQ$

    考虑固定前缀,只改变个位数,因为个位数的贡献为1,所以$f$的贡献也会各不相同,又因为$fin[0,9]$,所以$[1,9],[10,19],[20,21],...$的贡献就都是45.

    (开始呆呆$lq$还懵了一下,,,想着为啥不是$[1,10],[11,20],...$这样儿的.然后就想起了固定前缀$kk$

    于是现在$sum_{i=1}^n f(n)$就变形为了,$45cdot frac{n+1}{10}+sum_{i=frac{n+1}{10}cdot 10}^n f(n)$

    现在只要考虑求$sum_{i=frac{n+1}{10}cdot 10}^n f(n)$.

    依然是前面说的,固定前缀后只有个位数改变时.因为个位数贡献为1,所以相差在不膜10的意义下也一定是1.

    所以求一个其他递推出来就成$QwQ$

    $over$

    这题主要就是要发现关于这个$f$的几个奇奇怪怪的性质$QwQ$.

    嗷记得开$ll$鸭

     

    #include<bits/stdc++.h>
    using namespace std;
    #define il inline
    #define gc getchar()
    #define int long long
    #define ri register int
    #define rb register bool
    #define rc register char
    #define rp(i,x,y) for(ri i=x;i<=y;++i)
    #define my(i,x,y) for(ri i=x;i>=y;--i)
    
    int d[20];
    
    il int read()
    {
        rc ch=gc;ri x=0;rb y=1;
        while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
        if(ch=='-')ch=gc,y=0;
        while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
        return y?x:-x;
    }
    il int f(ri x)
    {
        ri cnt=0;memset(d,0,sizeof(d));
        while(x){d[++cnt]=x%10,x/=10;}
        while(cnt>1){rp(i,1,cnt-1)d[i]=(d[i]+d[i+1])%10;--cnt;while(!d[cnt] && cnt>0)--cnt;}
        return d[1];
    }
    il int cal(ri x){ri d1=(x+1)/10,d2=d1*10,ret=f(d2),as=d1*45;while(d2<=x)as+=ret,(++ret)%=10,++d2;return as;}
    
    signed main()
    {
        //freopen("1076.in","r",stdin);freopen("1076.out","w",stdout);
        ri T=read();
        while(T--){ri l=read(),r=read();printf("%lld
    ",cal(r)-cal(l-1));}
        return 0;
    }
    View Code

     

  • 相关阅读:
    Git全局配置备忘
    Wpf之Microsoft.Extensions.DependencyInjection
    Wpf之Interaction.Triggers与Interaction.Behaviors
    Wpf之异步绑定
    Wpf之HandyControls与MaterialDesign混用之DataGrid
    WPF将log4net配置文件设置为资源来保护配置文件
    c# PInvoke根据工程配置自动引用正确的dlls
    Wpf的gRpc的Server/Client
    Python必会的单元测试框架 —— unittest
    网易centos yum源
  • 原文地址:https://www.cnblogs.com/lqsukida/p/11622631.html
Copyright © 2011-2022 走看看