题意:a是严格递增数列,bi是ai每一位的和,告诉你b1~bn,问你怎样搞才能让an最小

思路:让ai刚好大于ai-1弄出来的an最小。所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生成比前一个数大的数,那么就和前一个数保持一致,否则当前位 = 前一个数当前位+ 1,后面的位数按照最小方式排列。如果排到最后每一位都和前面一个数一致,就把剩余的b从最小的一位一直加满9。

代码:

#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = + ;
const int MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
int b[maxn], ans[maxn][maxn + ], cnt[maxn];
void solve1(int i){
cnt[i] = ;
while(b[i] > ){
ans[i][cnt[i]++] = ;
b[i] -= ;
}
ans[i][cnt[i]++] = b[i];
}
int main(){
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &b[i]);
} solve1();
for(int i = ; i <= n; i++){
if(b[i] - * cnt[i - ] > ){
solve1(i);
}
else{
if(b[i] <= ans[i - ][cnt[i - ] - ]){
cnt[i] = cnt[i - ] + ;
ans[i][cnt[i] - ] = ;
b[i]--;
for(int j = ; j < cnt[i] - ; j++){
if(b[i] >= ){
ans[i][j] = ;
b[i] -= ;
}
else if(b[i] > ){
ans[i][j] = b[i];
b[i] = ;
}
else ans[i][j] = ;
}
}
else{
cnt[i] = cnt[i - ];
for(int j = cnt[i] - ; j >= ; j--){
if(j != ){
if(b[i] - ans[i - ][j] <= ans[i - ][j - ]){
ans[i][j] = ans[i - ][j] + ;
b[i] -= ans[i][j];
while(ans[i][j] > ){
b[i] += ans[i][j] - ;
j++;
if(j == cnt[i]){
ans[i][j] = ;
cnt[i]++;
}
ans[i][j]++;
} for(int k = ; k < j; k++){
if(b[i] >= ){
ans[i][k] = ;
b[i] -= ;
}
else if(b[i] > ){
ans[i][k] = b[i];
b[i] = ;
}
else ans[i][k] = ;
}
break;
}
else{
ans[i][j] = ans[i - ][j];
b[i] -= ans[i][j];
}
}
else{
ans[i][j] = ans[i - ][j];
b[i] -= ans[i][j];
}
}
if(b[i] > ){
for(int j = ; j < cnt[i] && b[i] > ; j++){
if(b[i] > - ans[i][j]){
b[i] -= - ans[i][j];
ans[i][j] = ;
}
else{
ans[i][j] += b[i];
b[i] = ;
}
}
}
}
}
}
for(int i = ; i <= n; i++){
for(int j = cnt[i] - ; j >= ; j--)
printf("%d", ans[i][j]);
printf("\n");
}
return ;
}

CodeForces 509C Sums of Digits(贪心乱搞)题解的更多相关文章

  1. Codeforces 509C Sums of Digits 贪心

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

  2. Codeforces 509C Sums of Digits

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

  3. codeforces 653C C. Bear and Up-Down(乱搞题)

    题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  4. Codeforces 723c [贪心][乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一个n和m. 第二行给n个数. 每次操作可以把n个数中的任何一个数替代为别的数,问最少的操作次数使得1.2.3.4.5...m中的数出现的次数 ...

  5. [CF752D]Santa Claus and a Palindrome(优先队列,贪心乱搞)

    题目链接:http://codeforces.com/contest/752/problem/D 题意:给长度为k的n个字符串,每一个字符串有权值,求构造一个大回文串.使得权值最大. 因为字符串长度都 ...

  6. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  7. [luoguP1053] 篝火晚会(贪心 + 乱搞)

    传送门 假设第一个位置是1,那么枚举它的左右两边是谁,有两种情况,然后可以递推求出序列. 然后可以贪心,两个序列有多少个不同的数,答案就是多少,具体为啥,yy一下即可 然后就是判断递推求出的序列和目标 ...

  8. FJNU2018低程F jq解救fuls (贪心乱搞)题解

    题目描述 一天fuls被邪恶的"咕咕咕"抓走了,jq为了救fuls可谓是赴汤蹈火,费了九牛二虎之力才找到了"咕咕咕"关押fuls的地方. fuls被关在一个机关 ...

  9. CodeForces 81D.Polycarp's Picture Gallery 乱搞

    D. Polycarp's Picture Gallery time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 如何在Sitecore CMS中创建项目

    从功能区 打开Sitecore的内容编辑器,选择内容树中的项目.创建的项目将作为所选项目的子项添加. Sitecore 8显示所选的Home项目 Sitecore 6和7显示所选的Home项目 功能区 ...

  2. request.getServletPath(),request.getContextPath()

    2018-11-24  16:34:33 1. getServletPath():获取能够与“url-pattern”中匹配的路径,注意是完全匹配的部分,*的部分不包括. 2. getPageInfo ...

  3. 用Django实现Video页面分类查询

    Model表创建,Url映射,Views函数处理,Html生成 根据上图,视频方向与视频分类是多对多的关系,视频分类与视频信息是一对多的关系,难度级别是单一的查询条件(与之前俩者并无关系) Model ...

  4. Web API 跨域请求

    分布式技术在项目中会频繁用到,以前接触过WebService(可跨平台).WCF(功能强大,配置繁琐),    最近由于上层业务调整,将原来的MVC项目一分为三,将数据层提取出来,用API去访问.然后 ...

  5. java及spark2.X连接mongodb3.X单机或集群的方法(带认证及不带认证)

    首先,我们明确的是访问Mongos和访问单机Mongod并没有什么区别.接下来的方法都是既可以访问mongod又可以访问Mongos的. 另外,读作java写作scala,反正大家都看得懂...... ...

  6. VPS采用的几种常见技术(OVZ、Xen、KVM)介绍与对比

    很多人看到同样配置的VPS价格相差很大,甚是不理解,其实VPS使用的虚拟技术种类有很多,如OpenVZ.Xen.KVM.Xen和HVM与PV. 在+XEN中pv是半虚拟化,hvm是全虚拟化,pv只能用 ...

  7. TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow

    TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow 只需在cmd中输入pip ...

  8. FAQ About WOYO PDR007 Dent Removal Heat Induction System

    WOYO PDR 007 is a dent repair tool for auto maintence. WOYO PDR007 Auto Body Paintless Dent Repair K ...

  9. 使用GoldenGate初始化的两种方式

    在使用OGG开始增量数据的实时复制之前,一般需要对当前的存量数据进行初始化,如果是同构数据库,则可以使用数据库自带的工具完成,比如Oracle DB中的rman, expdp/impdp等. 其实og ...

  10. Server Library [Apache Tomcat 7.0] unbound解决方案

    问题描述: 当在MyEclipse中导入高版本Eclipse的[Eclipse Dynamic Web]项目后,会发现其Java Build Path(选定项目->Alt+Enter即可打开Pr ...