zoukankan      html  css  js  c++  java
  • #1033 : 交错和

    #1033 : 交错和

    时间限制:10000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an - 1,定义交错和函数:

    f(x) = a0 - a1 + a2 - ... + ( - 1)n - 1an - 1

    例如:

    f(3214567) = 3 - 2 + 1 - 4 + 5 - 6 + 7 = 4

    给定 

    1405402477702.png

    输入

    输入数据仅一行包含三个整数,l, r, k(0 ≤ l ≤ r ≤ 1018, |k| ≤ 100)。

    输出

    输出一行一个整数表示结果,考虑到答案可能很大,输出结果模 109 + 7。

    提示

    对于样例 ,满足条件的数有 110 和 121,所以结果是 231 = 110 + 121。

    更多样例:

    Input
    4344 3214567 3
    Output
    611668829
    Input
    404491953 1587197241 1
    Output
    323937411
    Input
    60296763086567224 193422344885593844 10
    Output
    608746132
    Input
    100 121 -1
    Output
    120
    样例输入
    100 121 0
    样例输出
    231
    分析:与恨7不成妻类似,数位dp维护两个东西,个数和值即可;
       (a1+p)+(a2+p)+...+(an+p)=(a1+a2+...+an)+p*n;
       注意前导0;
    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <bitset>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<ll,ll>
    #define piii pair<int,pair<ll,ll> >
    #define sys system("pause")
    const int maxn=1e5+10;
    const int N=5e4+10;
    const int M=N*10*10;
    using namespace std;
    inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline void umax(ll &p,ll q){if(p<q)p=q;}
    inline void umin(ll &p,ll q){if(p>q)p=q;}
    int n,m,k,t,num[20],pos;
    pii dp[20][500][3];
    bool vis[20][500][3];
    ll p,q,tp[20];
    pii dfs(int pos,int x,int y,int z)
    {
        if(pos<0)return mp(x==200,0);
        if(y&&z&&vis[pos][x][z+1])return dp[pos][x][z+1];
        int now=y?9:num[pos],i;
        pii ret=mp(0,0);
        rep(i,0,now)
        {
            pii v=dfs(pos-1,x-(!z&&i?1:z)*i,y||i<num[pos],(!z&&i?-1:-z));
            ret.fi+=v.fi;
            ret.fi%=mod;
            ret.se+=v.se+i*v.fi%mod*tp[pos]%mod;
            ret.se%=mod;
        }
        if(y&&z)vis[pos][x][z+1]=true,dp[pos][x][z+1]=ret;
        return ret;
    }
    ll gao(ll x)
    {
        if(x<0)return 0;
        pos=0;
        while(x)num[pos++]=x%10,x/=10;
        return dfs(pos-1,k+200,0,0).se;
    }
    int main()
    {
        int i,j;
        tp[0]=1;
        rep(i,1,19)tp[i]=tp[i-1]*10%mod;
        scanf("%lld%lld%d",&p,&q,&k);
        printf("%lld
    ",(gao(q)-gao(p-1)+mod)%mod);
        return 0;
    }
  • 相关阅读:
    LightOJ--1094-- Farthest Nodes in a Tree(树的直径裸题)
    poj--1383--Labyrinth(树的直径)
    C字符数组和C++字符串
    Miracl库学习
    GBDT学习
    Java编程规范
    关于JS中的数组[]的方法
    焦点离开事件
    Firebug 安装方法
    JAVASE 中的String的字符串
  • 原文地址:https://www.cnblogs.com/dyzll/p/6405905.html
Copyright © 2011-2022 走看看