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]位数一定大于等于前一个 ...
随机推荐
- Paper Reading: Perceptual Generative Adversarial Networks for Small Object Detection
Perceptual Generative Adversarial Networks for Small Object Detection 2017-07-11 19:47:46 CVPR 20 ...
- python学习 day05打卡
今天可变学习的主要内容是 : 本节主要内容: 1.字典的简单介绍 2.字典增删改查和其他操作 3.字典的嵌套 一.字典的简单介绍 字典(dict)是pytho中唯一的一个映射类型.它是以{}括起来的键 ...
- python接口测试模版
"""Test case implementation""" import sys import functools import diff ...
- Oracle Initialzation error instantclient_11_2 32位客户端问题
本地安装完oracle 用PLSql 连接是一堆的问题,折腾一上午终于解决了 下载一个 instantclient_11_2 32位的oracle客户端.放在oracle安装目录product下,在把 ...
- 【Python】【有趣的模块】【Requests】session & cookie
保存http请求的状态(请求的上下文) [区别&联系] 1. cookie保存在客户端的浏览器,比如标识是哪个请求者.购物车应用等 session保存在服务端,http连接时无则创建,有则用现 ...
- tornado tcp 框架 demo
server #!/usr/bin/env python import logging from tornado.ioloop import IOLoop from tornado import ge ...
- 文件编码检测.ZC
1.今天(20181101) 发现 g文件中的 xml头 和 文件编码不一致,最后发现 貌似是我搞错了,人家的文件 编码方式写的是对的. 我发现的现象是:XML里面写的是"GBK" ...
- file类中,命令记录
file的长度>>4096当前盘符总空间字节数>>>151200460800当前盘符的可用空间字节数>>>143769821184 long a = f ...
- 《剑指offer》第六十二题(圆圈中最后剩下的数字)
// 面试题62:圆圈中最后剩下的数字 // 题目:0, 1, …, n-1这n个数字排成一个圆圈,从数字0开始每次从这个圆圈里 // 删除第m个数字.求出这个圆圈里剩下的最后一个数字. #inclu ...
- input 输入值的监听 禁止输入特殊字符
1.input 输入值的监听 //用于监听input的值变化(input的值产生变化才会触发事件) (function ($) { $.fn.watch = function (callback) ...