Sums of Digits CodeForces - 509C (贪心,模拟)
大意: 一个未知严格递增数组$a$, 给定每个数的数位和, 求$a[n]$最小的数组$a$
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 310, M = 1e4+10;
int n, a[N];
int num[N][M+1]; void solve(int id, int s) {
int sum = 0, pos = 0, res = 0;
REP(i,1,M) {
if (num[id-1][i]!=9) {
int l = num[id-1][i]+1+sum;
int r = 9*(M-i+1)+sum;
if (l<=s&&s<=r) {
pos = i, res = sum;
}
}
sum += num[id-1][i];
}
REP(i,1,pos-1) num[id][i]=num[id-1][i];
PER(i,num[id-1][pos]+1,9) {
int l=i+res;
int r=i+9*(M-pos)+res;
if (l<=s&&s<=r) {
num[id][pos]=i;
}
}
res += num[id][pos];
REP(i,pos+1,M) {
PER(j,0,9) {
int l=res+j,r=j+9*(M-i)+res;
if (l<=s&&s<=r) num[id][i]=j;
}
res += num[id][i];
}
} int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
REP(i,1,n) solve(i,a[i]);
REP(j,1,n) {
int pos = 1;
while (!num[j][pos]) ++pos;
REP(i,pos,M) putchar(num[j][i]+'0');hr;
}
}
Sums of Digits CodeForces - 509C (贪心,模拟)的更多相关文章
- CodeForces - 730A 贪心+模拟
贪心策略: 1.只有一个最大值,选着第二大的一起参加比赛减分. 2.有奇数个最大值,选择三个进行比赛. 3.偶数个最大值,选择两个进行比赛. 为什么不把最大值全部选择? 因为最多只能选五个,有可能选择 ...
- Population Size CodeForces - 416D (贪心,模拟)
大意: 给定$n$元素序列$a$, 求将$a$划分为连续的等差数列, 且划分数尽量小. $a$中的$-1$表示可以替换为任意正整数, 等差数列中必须也都是正整数. 贪心策略就是从前到后尽量添进一个等差 ...
- Arthur and Questions CodeForces - 518E (贪心模拟)
大意: 给定序列$a$, 某些位置为'?', 求给'?'赋值使得序列$(a_1+a_2+...+a_k,a_2+a_3+...+a_{k+1},...)严格递增, 且$\sum|a_i|$最小. 化简 ...
- Codeforces 1042C (贪心+模拟)
题面 传送门 分析 思路简单,但代码较复杂的贪心 分类讨论: 有0 负数有奇数个:将绝对值最小(实际最大)的负数和0全部乘到一起,最后删掉0 负数有偶数个:将0全部乘到一起,最后删掉0 没有0 负数有 ...
- Music in Car CodeForces - 746F (贪心,模拟)
大意: n首歌, 第$i$首歌时间$t_i$, 播放完获得贡献$a_i$, 最多播放k分钟, 可以任选一首歌开始按顺序播放, 最多选w首歌半曲播放(花费时间上取整), 求贡献最大值. 挺简单的一个题, ...
- [codeforces 509]C. Sums of Digits
[codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- CodeForces ---596B--Wilbur and Array(贪心模拟)
Wilbur and Array Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Su ...
- [模拟]Codeforces509C Sums of Digits
题目链接 题意:给n个数a[i], 要求b[i]每位数的和等于a[i], 并且b[i]要严格递增 求最小的b[i] b[0]最小一定是X9999...这样的形式 后面的b[i]位数一定大于等于前一个 ...
随机推荐
- Derek解读Bytom源码-P2P网络 地址簿
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- CAS Client集群环境的Session问题及解决方案介绍,下篇介绍作者本人项目中的解决方案代码
CAS Client集群环境的Session问题及解决方案 程序猿讲故事 2016-05-20 原文 [原创申明:文章为原创,欢迎非盈利性转载,但转载必须注明来源] 之前写过一篇文章,介绍单点登 ...
- Linux shell 计算两个文件的并集、交集、差集
假设我们现在有两个文件 a.txt .b.txt a.txt 中的内容如下: a c 1 3 d 4 b.txt 中的内容如下: a b e 2 1 5 # Example 01 计算并集: [roo ...
- 获得WebBrowser中的图片数据
/// <summary> /// 获取WebBrowser指定的图片 /// </summary> /// <param name="webBrowser&q ...
- 2018.3 江苏省计算机等级考试 C语言 编程题答案
题目要求:给定一个数字范围,输出满足这些条件: 1.能被3整除: 2.包含数字5, 将满足的数字放在特定的数组里输出.输出这些数里5出现的个数.数字的个数. 想起来有点伤心,本来很简单的题,考试的时候 ...
- 【BZOJ】3143: [Hnoi2013]游走
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3143 显然如果一条边期望被走过的次数越多,我们就应该给它的编号越小. 所以问题变为如何求每 ...
- Codeforces 767D - Cartons of milk
题目链接:http://codeforces.com/contest/767/problem/D D比C水系列. 将商店里面的牛奶按照保质期升序排序(显然优先买保质期久的)考虑二分答案,然后再将整个序 ...
- 在使用Java8并行流时的问题分析
最近在使用Java8的并行流时遇到了坑,线上排查问题时花了较多时间,分享出来与大家一起学习与自查 // 此处为坑 List<Java8Demo> copy = Lists.newArray ...
- chrome driver 下载
https://npm.taobao.org/mirrors/chromedriver/ 解压后,把路径放到系统环境变量中即可 dirver = webdriver.Chrome()
- django认证系统 Authentication
Django自带一个用户认证系统,用于处理用户账户.群组.许可和基于cookie的用户会话. Django的认证系统包含了身份验证和权限管理两部分.简单地说,身份验证用于核实某个用户是否合法,权限管理 ...