C. Sums of Digits
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output

Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.

Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.

It is guaranteed that such a sequence always exists.

Input

The first line contains a single integer number n (1 ≤ n ≤ 300).

Next n lines contain integer numbers b1, ..., bn  — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.

Output

Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.

If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.

Sample test(s)
input
3
1
2
3
output
1
2
3
input
3
3
2
1
output
3
11
100 题意是给你一个递增序列的每个数的各位数字之和,求还原这个数列
显然贪心,每次用比上一个数大的最小的那个就行了
但是这题模拟实现太蛋疼了
而且极限数据是一开始a[1]=300要凑出3后面33个9,然后a[2]到a[300]是299个1……这样只开300零几位的就死了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7fffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,len;
int a[500],s[500],t[500];
inline void calc(int x,int l)
{
memset(s,0,sizeof(s));
len=0;x--;s[l]=1;
while (x>=9&&len<l)
{
s[++len]=9;
x-=9;
}
if (x)s[++len]+=x;
len=l;
}
inline bool getmn(int x)
{
t[len+1]=0;
for (int i=len;i>=1;i--)
t[i]=t[i+1]+s[i];
for (int i=1;i<=len;i++)
{
if (t[i]+1>x||s[i]==9)continue;
s[i]++;
while (x>9*(i-1)+t[i+1]+s[i]&&s[i]<9)s[i]++;
if (x>9*(i-1)+t[i+1]+s[i])continue;
x=x-(t[i+1]+s[i]);
int now=1;
while(now<i&&x>=9)
{
s[now++]=9;
x-=9;
}
if (now!=i)s[now++]=x;
for (int j=now;j<i;j++)s[j]=0;
return 1;
}
return 0;
}
inline void put()
{
for (int i=len;i>=1;i--)
printf("%d",s[i]);
printf("\n");
}
int main()
{
n=read();
for (int i=1;i<=n;i++)a[i]=read();
calc(a[1],a[1]/9+(a[1]%9!=0));
put(); for (int i=2;i<=n;i++)
{
if (a[i]>9*len)calc(a[i],a[i]/9+(a[i]%9!=0));
if (!getmn(a[i]))calc(a[i],max(a[i]/9+(a[i]%9!=0),len+1));
put();
}
}

cf509C Sums of Digits的更多相关文章

  1. [codeforces 509]C. Sums of Digits

    [codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...

  2. 【codeforces 509C】Sums of Digits

    [题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...

  3. [模拟]Codeforces509C Sums of Digits

    题目链接 题意:给n个数a[i], 要求b[i]每位数的和等于a[i], 并且b[i]要严格递增 求最小的b[i] b[0]最小一定是X9999...这样的形式 后面的b[i]位数一定大于等于前一个 ...

  4. Codeforces 509C Sums of Digits

    http://codeforces.com/contest/509/problem/C  题目大意: 给出一个序列,代表原序列对应位置数的每一位的数字之和,原序列单调递增,问原序列的最后一个数最小的方 ...

  5. Codeforces 509C Sums of Digits 贪心

    这道题目有人用DFS.有人用DP 我觉得还是最简单的贪心解决也是不错的选择. Ok,不废话了,这道题目的意思就是 原先存在一个严格递增的Arrary_A,然后Array_A[i] 的每位之和为Arra ...

  6. CodeForces 509C Sums of Digits(贪心乱搞)题解

    题意:a是严格递增数列,bi是ai每一位的和,告诉你b1~bn,问你怎样搞才能让an最小 思路:让ai刚好大于ai-1弄出来的an最小.所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生 ...

  7. Sums of Digits CodeForces - 509C (贪心,模拟)

    大意: 一个未知严格递增数组$a$, 给定每个数的数位和, 求$a[n]$最小的数组$a$ #include <iostream> #include <algorithm> # ...

  8. AtCoder Beginner Contest 083 (AB)

    A - Libra 题目链接:https://abc083.contest.atcoder.jp/tasks/abc083_a Time limit : 2sec / Memory limit : 2 ...

  9. codeforce - 13A A.Numbers

    A. Numbers time limit per test 1 second memory limit per test 64 megabytes input standard input outp ...

随机推荐

  1. Linux系统下查看某文件修改的时间戳

    Linux系统下查看某文件修改的时间戳查看文件时间戳命令:stat awk.txt File: `awk.txt' Size: 20              Blocks: 8          I ...

  2. test_wifi

    #!/system/bin/sh #Load driver echo "ASD WIFI TESTING..." AP_NAME="default" num=0 ...

  3. Amoeba是一个类似MySQL Proxy的分布式数据库中间代理层软件,是由陈思儒开发的一个开源的java项目

    http://www.cnblogs.com/xiaocen/p/3736095.html amoeba实现mysql读写分离 application  shang  2年前 (2013-03-28) ...

  4. 关于“无法解析的外部符号”和“该符号在函数_wmain 中被引用”的问题

    在VS2008和opendv的环境下: error LNK2019: 无法解析的外部符号_cvDestroyWindow,该符号在函数_wmain 中被引用 error LNK2019: 无法解析的外 ...

  5. 指针-->字符串

    1. 以字符串形式出现的,编译器都会为该字符串自动添加一个0作为结束符. 如在代码中写"abc",那么编译器帮你存储的是"abc\0". 2. "ab ...

  6. C#递归搜索指定目录下的文件或目录

    诚然可以使用现成的Directory类下的GetFiles.GetDirectories.GetFileSystemEntries这几个方法实现同样的功能,但请相信我不是蛋疼,原因是这几个方法在遇上[ ...

  7. 在linux后台执行脚本

    1. 使用&符号在后台执行命令 你可以在Linux命令或者脚本后面增加&符号,从而使命令或脚本在后台执行,例如:. $ ./my-shell-script.sh & 2. 使用 ...

  8. gradle命令

    gradle tasks 可以显示gradle可以做的任务. gradle build 就会生成jar包. build和clean install的作用是否一致?

  9. Nopcommerce商城添加【满XX减XX优惠券】功能

    公司的电商网站要做个优惠券的功能,nop框架,但我接触nop时间不多,最后还是为了功能而完成了.这中间肯定有很多小问题. Nopcommerce自带的促销功能感觉不是很好,首先优惠券功能放在购物车页面 ...

  10. 在Oracle中查询表的大小、表的占用情况和表空间的大小

    转载自http://blog.csdn.net/cuker919/article/details/8514253 select segment_name, bytes as 大小 from user_ ...