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]位数一定大于等于前一个 ...
随机推荐
- CentOS7 系统升级,删除centos7开机界面多余选,升级至最新的内核
一:升级系统 1.检查系统版本: [root@localhost /]# cat /etc/redhat-release CentOS Linux release (Core) 2.运行yum命令升级 ...
- 【做题】arc080_f-Prime Flip——转换、数论及匹配
题意:有一个无限序列,其中有\(n\)个位置上的数为\(1\),其余都是\(0\).你可以进行若干次操作,每次选取序列上的一个区间\([l,r)\),满足\(r-l\)为奇质数,将在这个区间上的数都异 ...
- js希尔排序
function shellSort (arr) { var len = arr.length; var increment = Math.floor(len/2); while(increment! ...
- 解决Android Studio No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.50 available for offline mode.
打开 file --> Settings... --> Build,Execution,Deployment下点击 Gradle 在Global Gradle settings 处 取消勾 ...
- SAP 供应商/客户的冻结及其删除操作
SAP 供应商/客户的冻结及其删除操作 在SAP中,有所谓的财务供应商(Tcode:FK01)和后勤供应商(Tcode:XK01),供应商和客户主数据包括一般数据/公司代码数据/采购组织|销售范围三方 ...
- 20165306学习基础和C语言基础调查
20165306学习基础和C语言基础调查 技能学习心得 我认为兴趣.责任感.毅力对技能的获得非常重要. 因为我从小五音不全.肢体不协调,所以看春晚等节目的时候会把更多的关注点放在主持人身上.小时候觉得 ...
- python实现八皇后问题
import random def judge(state, nextX): #判断是否和之前的皇后状态有冲突 nextY = len(state) for i in range(nextY): if ...
- HDU 5452 Minimum Cut(LCA)
http://acm.hdu.edu.cn/showproblem.php?pid=5452 题意: 有一个连通的图G,先给出图中的一棵生成树,然后接着给出图中剩余的边,现在要删除最少的边使得G不连通 ...
- gitlab git
git网站是进不去的需要加权限才能进去!!!!!!!! 登录进去后 ssh-keygen -t rsa -C "gitlab用户名一般是邮箱" 一路设置好 Use the code ...
- css的postion属性
在实际项目中,发现postion这个属性经常使用而且常常很重要,所以总结整理一下知识点 css中postion属性有以下可选值,分别是:static,absolute, fixed, relative ...