zoukankan      html  css  js  c++  java
  • XJOI网上同步训练DAY5 T3

     就是对于一个数,我们去考虑把t*****减到(t-1)9999*的代价。

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<iostream>
     6 #include<map>
     7 #define ll long long
     8 typedef std::pair<ll,int> info;
     9 std::map<info,info>mp;
    10 ll p[20],n;
    11 ll read(){
    12     ll t=0,f=1;char ch=getchar();
    13     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    14     while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();}
    15     return t*f;
    16 }
    17 info calc(int idx,info x){
    18     if (idx==1){
    19         if (x.first>=x.second) return info(1,0);
    20         else return info(0,x.first);
    21     }
    22     if (mp.find(x)!=mp.end()) return mp[x];
    23     int t=x.first/p[idx-1];
    24     ll num=x.first-t*p[idx-1];
    25     info ans(0,0);
    26     for (int i=t;i>0;i--){
    27         info res=calc(idx-1,info(num,std::max(i,x.second)));
    28         ans.first+=res.first+1;
    29         num=p[idx-1]+res.second-std::max(i,x.second);
    30     }
    31     info res=calc(idx-1,info(num,x.second));
    32     ans.first+=res.first;ans.second+=res.second;
    33     return mp[x]=ans;
    34 }
    35 int main(){
    36     n=read();
    37     p[0]=1;
    38     for (int i=1;i<=18;i++) p[i]=p[i-1]*10;
    39     int len=0;
    40     for (ll x=n;x;x/=10) len++;
    41     if (n==0) puts("0");
    42     else printf("%lld
    ",calc(len,info(n,0)).first);
    43     return 0;
    44 }
  • 相关阅读:
    测试用例的优先级的概念
    Day02.测试用例和测试方法
    day01.测试理论
    开发python 面试题
    4.路径页面接口开发
    ps命令没有显示路径找到命令真实路径
    Linux软链接和硬链接
    Linux文件元数据和节点表结构
    jinjia2语言
    Ansible之YAML语言
  • 原文地址:https://www.cnblogs.com/qzqzgfy/p/5629814.html
Copyright © 2011-2022 走看看