【AtCoder】AGC011 E - Increasing Numbers
题解
题是真的好,我是真的不会做
智商本还是要多开啊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的更多相关文章
- 【AtCoder】AGC011
AGC011 A - Airport Bus 大意:有N个人,每个人只能在\([T_i,T_i +K]\)这段区间乘车,每辆车安排C人,问最少安排几辆车 直接扫,遇到一个没有车的在\(T_i +K\) ...
- 【AtCoder】AGC011 D - Half Reflector
题解 大意是n个管子排成一排,每个管子有两种状态,A状态是从某个方向进去,从原方向出来,B状态是从某个方向进去,从另一个方向出来 球经过一个A状态的管子这个管子会立刻变成B状态,经过一个B状态的管子会 ...
- 【AtCoder】AGC011 C - Squared Graph
题解 大意是给出一张图,然后建一张新图,新图的点标号是(a,b) 如果a和c有一条边,b和d有一条边,那么(a,b)和(c,d)之间有一条边 我们把这道题当成这道题来做,给出两张图,如果第一张图有边( ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- 【题解】Greatest Common Increasing Subsequence
[题解]Greatest Common Increasing Subsequence vj 唉,把自己当做DP入门选手来总结这道题吧,我DP实在太差了 首先是设置状态的技巧,设置状态主要就是要补充不漏 ...
- 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)
[LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...
- 【LeetCode】165. Compare Version Numbers 解题报告(Python)
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
随机推荐
- TCP、UDP绑定同一端口通信的解释
昨日突然讨论起TCP与UDP是否可以在同一端口进行绑定,通信. 在印象当中我记得是可以的,今日google了相关资料, 确定以及肯定的: TCP.UDP可以绑定同一端口来进行通信: 网络中可以被命名和 ...
- MacOS Sierra允许运行任何来源的程序
参考自http://bbs.feng.com/read-htm-tid-10584598.html Mac新系统 Sierra中默认已经看不到“任何来源”的选项,就无法安装很多的第三方程序,所以需要做 ...
- grpc-gateway:grpc转换为http协议对外提供服务
我所在公司的项目是采用基于Restful的微服务架构,随着微服务之间的沟通越来越频繁,就希望可以做成用rpc来做内部的通讯,对外依然用Restful.于是就想到了google的grpc. 使用grpc ...
- 【转】Elastic日报 第576期 (2019-04-05)
1.Elasticsearch性能测试实践http://t.cn/EiRzFiI2.监控Elasticsearch的插件推荐http://t.cn/EiRzFix3.支持机器数据的可扩展Elastic ...
- 基本控件文档-UIButton属性
CHENYILONG Blog 基本控件文档-UIButton属性 Fullscreen UIButton属性技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博ht ...
- HDU 1251 统计难题 (裸的字典树)
题目链接 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...
- js_模块化
https://www.cnblogs.com/scq000/p/10647128.html
- UNIX环境高级编程 第14章 高级I/O
这一章涉及很多概念和函数,包括:非阻塞I/O.记录锁.I/O复用.异步I/O.readv和writev函数以及内存映射. 非阻塞I/O 在Unix中,可以将系统调用分为两种,一种是“低速”系统调用,另 ...
- jQuery选择器——(三)
1.基本元素选择器 id选择器:$(“#id名称”); 元素选择器:$(“元素名称”); 类选择器:$(“.类名”); 通配符:* 多个选择器共用(并集) 2.层级选择器 ancestor desce ...
- 配置虚拟机时间使其与国内时间同步,linux时间 ntp
设置系统时间 [root@node2 ~]# date -s "10/30/18 09:30:00"Tue Oct 30 09:30:00 PDT 2018[root@node2 ...