题解

题是真的好,我是真的不会做
智商本还是要多开啊QwQ

我们发现一个非下降的数字一定可以用不超过九个1111111111...1111表示

那么我们可以得到这样的一个式子,假如我们用了k个数,那么最多的话可以是这样的
\(N = \sum_{i = 1}^{9k} (10^{r_i} - 1) / 9\)
\(9N + 9k = \sum_{i = 1}^{9k} 10^{r_{i}}\)

我们只要每次计算出9N + 9 ,9N + 18...,然后看看十进制下每一位的数字和有没有超过9k,直接加的话最坏情况是一次操作\(O(L)\)的,但是大家应该都有种直觉总的操作就是\(O(L)\)的……就是势能分析啦,不太会证,就是一次长的进位过后之后不会再进位了。。。

复杂度\(O(lg N)\)

代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#include <queue>
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define pb push_back
#define mo 974711
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define MAXN 200005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 - '0' + c;
    c = getchar();
    }
    res = res * f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
struct Bignum {
    vector<int> v;
    int sum;
    Bignum operator = (string s) {
    v.clear();
    sum = 0;
    for(int i = s.length() - 1 ; i >= 0 ; --i) {
        v.pb(s[i] - '0');
        sum += s[i] - '0';
    }
    return *this;
    }
    friend Bignum operator * (const Bignum &a,const int b) {
    int s = a.v.size();
    Bignum c;c.v.clear();
    for(int i = 0 ; i <= s ; ++i) c.v.pb(0);
    int g = 0;
    for(int i = 0 ; i < s ; ++i) {
        int x = a.v[i] * b + g;
        c.v[i] = x % 10;
        g = x / 10;
    }
    if(g) c.v[s] = g;
    for(int i = s ; i > 0 ; --i) {
        if(c.v[i] == 0) c.v.pop_back();
        else break;
    }
    c.sum = 0;s = c.v.size();
    for(int i = 0 ; i < s ; ++i) c.sum += c.v[i];
    return c;
    }
}A;
string s;
void Solve() {
    cin>>s;
    A = s;
    A = A * 9;
    int ans = 0;
    while(1) {
    int s = A.v.size();
    int g = 9;
    for(int i = 0 ; i < s ; ++i) {
        if(!g) break;
        A.sum -= A.v[i];
        int x = A.v[i] + g;
        A.v[i] = x % 10;
        A.sum += A.v[i];
        g = x / 10;
    }
    if(g) A.v.pb(g),A.sum += g;
    ++ans;
    if(ans * 9 >= A.sum) break;
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

【AtCoder】AGC011 E - Increasing Numbers的更多相关文章

  1. 【AtCoder】AGC011

    AGC011 A - Airport Bus 大意:有N个人,每个人只能在\([T_i,T_i +K]\)这段区间乘车,每辆车安排C人,问最少安排几辆车 直接扫,遇到一个没有车的在\(T_i +K\) ...

  2. 【AtCoder】AGC011 D - Half Reflector

    题解 大意是n个管子排成一排,每个管子有两种状态,A状态是从某个方向进去,从原方向出来,B状态是从某个方向进去,从另一个方向出来 球经过一个A状态的管子这个管子会立刻变成B状态,经过一个B状态的管子会 ...

  3. 【AtCoder】AGC011 C - Squared Graph

    题解 大意是给出一张图,然后建一张新图,新图的点标号是(a,b) 如果a和c有一条边,b和d有一条边,那么(a,b)和(c,d)之间有一条边 我们把这道题当成这道题来做,给出两张图,如果第一张图有边( ...

  4. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  5. 【题解】Greatest Common Increasing Subsequence

    [题解]Greatest Common Increasing Subsequence vj 唉,把自己当做DP入门选手来总结这道题吧,我DP实在太差了 首先是设置状态的技巧,设置状态主要就是要补充不漏 ...

  6. 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)

    [LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...

  7. 【LeetCode】165. Compare Version Numbers 解题报告(Python)

    [LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  8. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  9. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

随机推荐

  1. Java Socket Timeout 总结

    原文出处:囚兔 摘要: Java的网络编程Socket常常用于各种网络工具,比如数据库的jdbc客户端,redis客户端jedis,各种RPC工具java客户端,这其中存在一些参数来配置timeout ...

  2. RAC转换传统的通信

    ///////////////////各种机制转信号/////////////////////////////// 1.UI事件 [self.logInButton rac_signalForCont ...

  3. 2015/12/14 Python网络编程,TCP/IP客户端和服务器初探

    一直不是很清楚服务器的定义,对于什么是服务器/客户端架构也只有一个模糊的感觉.最近开始学习,才明白一些什么服务器和客户端的关系. 所谓的服务器,就是提供服务的东西,它是一个硬件或者软件,可以向一个或者 ...

  4. 51 Free Data Science Books

    51 Free Data Science Books A great collection of free data science books covering a wide range of to ...

  5. windows设置代理.bat 脚本

    按照下列脚本复制到记事本中,保存,重命名后缀为.bat,使用时双击即可. 设置代理.bat,修改下列脚本中的代理地址和端口号 @echo off echo 开始设置IE代理上网 reg add &qu ...

  6. Spring MVC表单防重复提交

    利用Spring MVC的过滤器及token传递验证来实现表单防重复提交. 创建注解 @Target(ElementType.METHOD) @Retention(RetentionPolicy.RU ...

  7. 网页制作中最有用的免费Ajax和JavaScript代码库

    网上看到的一篇小文,挺有用的,收藏在这. 本文中,我整理了12个免费的Ajax和JavaScript代码库,可以帮助Web开发人员将应用程序提升到一个新水平. Ajax Instant Messeng ...

  8. Python练习-跨目录调用模块

    层级结构: dir1 ---hello.py dir2 ---main.py 其中,hello.py: def add(x,y): return x+y main.py如何能调用到hello.py中的 ...

  9. Linux服务-搭建Nginx

    任务目标:二进制安装nginx包,作为web服务修改配置文件,让配置生效,验证配置 首先使用yum 来安装 nginx 服务,基于epel-release平台的nginx需要epel的支持,所以要先安 ...

  10. UNIX环境高级编程 第11章 线程

    使用C++调用pthread_cleanup_push( )时,下面的代码是无法编译通过的: pthread_cleanup_push(cleanup, "thread 1 first ha ...