Codeforces 509C Sums of Digits
http://codeforces.com/contest/509/problem/C
题目大意:
给出一个序列,代表原序列对应位置数的每一位的数字之和,原序列单调递增,问原序列的最后一个数最小的方案每一个数是多少。
思路:贪心,从1到n,我们尽量让每个数最小就可以了。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int g[],n,a[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void work(int x,int y){
if (x==y){
g[]++;
int i=;
while (i<=g[]||g[i]>){
g[i+]+=g[i]/;
g[i]%=;
i++;
}
while (i>&&g[i]==) i--;
g[]=i;
x=;
for (int i=;i<=g[];i++)
x+=g[i];
}
if (x>y){
int j=,i;
for (i=;i<=g[]&&x-j>=y;i++) j+=g[i];
while (g[i]==) i++;
for(g[i--]++;i;i--) g[i]=;
int k=;
while (k<=g[]||g[k]>){
g[k+]+=g[k]/;
g[k]%=;
k++;
}
while (k>&&g[k]==) k--;
g[]=k;
x=;
for (int i=;i<=g[];i++)
x+=g[i];
}
int i;
for (i=;x<y;i++)
if (-g[i]+x>=y) g[i]+=y-x,x=y;
else x+=-g[i],g[i]=;
if (g[]<i-) g[]=i-;
}
int main(){
n=read();
for (int i=;i<=n;i++) a[i]=read();
for (int i=;i<=n;i++){
work(a[i-],a[i]);
for (int j=g[];j>=;j--)
printf("%d",g[j]);
puts("");
}
return ;
}
Codeforces 509C Sums of Digits的更多相关文章
- Codeforces 509C Sums of Digits 贪心
这道题目有人用DFS.有人用DP 我觉得还是最简单的贪心解决也是不错的选择. Ok,不废话了,这道题目的意思就是 原先存在一个严格递增的Arrary_A,然后Array_A[i] 的每位之和为Arra ...
- CodeForces 509C Sums of Digits(贪心乱搞)题解
题意:a是严格递增数列,bi是ai每一位的和,告诉你b1~bn,问你怎样搞才能让an最小 思路:让ai刚好大于ai-1弄出来的an最小.所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生 ...
- [codeforces 509]C. Sums of Digits
[codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...
- [模拟]Codeforces509C Sums of Digits
题目链接 题意:给n个数a[i], 要求b[i]每位数的和等于a[i], 并且b[i]要严格递增 求最小的b[i] b[0]最小一定是X9999...这样的形式 后面的b[i]位数一定大于等于前一个 ...
- cf509C Sums of Digits
C. Sums of Digits time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 【codeforces 509C】Sums of Digits
[题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...
- Sums of Digits CodeForces - 509C (贪心,模拟)
大意: 一个未知严格递增数组$a$, 给定每个数的数位和, 求$a[n]$最小的数组$a$ #include <iostream> #include <algorithm> # ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
- Codeforces 915 C. Permute Digits (dfs)
题目链接:Permute Digits 题意: 给出了两个数字a,b(<=1e18),保证a,b都不带前缀0.用a的字符重组一个数字使这个值最大且小于b.(保证这个值存在) 题解: 这题遇到了不 ...
随机推荐
- 【转】ipad死机了,无法退出,也无法关机,怎么办
原文网址:http://zhidao.baidu.com/link?url=oTz6J78hmtCAKddhwu1ITUiPmLnVJIaA_v_0dZblPaIJUhuMdyTCdS6H2737GX ...
- SPOJ694 -- DISUBSTR 后缀树组求不相同的子串的个数
DISUBSTR - Distinct Substrings Given a string, we need to find the total number of its distinct su ...
- UUID详解
什么是UUID? UUID是Universally Unique Identifier的缩写,它是在一定的范围内(从特定的名字空间到全球)唯一的机器生成的标识符.UUID具有以下涵义: 经由一定的算法 ...
- ios 限制输入长度
----------------UITextField限制输入的长度------------ - (BOOL)textField:(UITextField *)textField shouldChan ...
- Java中setCharAt()方法介绍
--转载自网络,备忘 这是StringBuffer类里面的一个方法:主要是用来替换的,方法里面有两个参数setCharAt(int index,Char ch),第一个参数是取代的位置 索引从0开始 ...
- Spring Data Redis—Pub/Sub(附Web项目源码)
一.发布和订阅机制 当一个客户端通过 PUBLISH 命令向订阅者发送信息的时候,我们称这个客户端为发布者(publisher). 而当一个客户端使用 SUBSCRIBE 或者 PSUBSCRIBE ...
- 一键注册控件的批处理(包含x86 和 x64)
@echo off if "%PROCESSOR_ARCHITECTURE%"=="x86" goto x86 if "%PROCESSOR_ARCH ...
- CentOS6.7 用户
1.添加普通用户[root@server ~]# useradd chenjiafa //添加一个名为chenjiafa的用户[root@server ~]# passwd chenjiafa ...
- Tooltip(提示框)组件
一.加载方式 //class加载方式 <a href="http://www.ycku.com" title="这是一个提示信息!" class=&quo ...
- VS2013服务器资源管理器添加Mysql数据源
如何为VS2013服务器资源管理器添加Mysql数据源,如图: 接下来就看下如何添加 1.需要下载安装Mysql for Visual Studio 1.1.1 下载位置:http://downloa ...