C. Given Length and Sum of Digits... (贪心)
https://codeforces.com/problemset/problem/489/C
C. Given Length and Sum of Digits...
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
input
2 15
output
69 96
input
3 0
output
-1 -1
题意:
给定一个数m 和 一个长度s,计算最大和最小在s长度下的十进制各位数和为m的值
注意如果无法生成,即输出两个-1
题解:
有个小坑,在输出最大值时得注意下k 是否为 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m, s, i, k;
cin >> m >> s;
if (s < 1 && m>1 || s > m * 9)
cout << -1 << " " << -1 << endl;
else {
for (i = m - 1, k = s; i >= 0; i--) {
int j = max(0, k - 9 * i);
if (j == 0 && i == m - 1 && k) j = 1;
cout << j;
k -= j;
}
cout << ' ';
for (i = m - 1, k = s; i >= 0; i--) {
int j = min(9, k);
cout << j;
k -= j;
}
}
}
C. Given Length and Sum of Digits... (贪心)的更多相关文章
- CodeForces 489C Given Length and Sum of Digits... (贪心)
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- codeforces#277.5 C. Given Length and Sum of Digits
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- CodeForces 489C Given Length and Sum of Digits... (dfs)
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...
- B - Given Length and Sum of Digits... CodeForces - 489C (贪心)
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and th ...
- CodeForces 489C (贪心) Given Length and Sum of Digits...
题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...
- Codeforces 489C Given Length and Sum of Digits...
m位长度,S为各位的和 利用贪心的思想逐位判断过去即可 详细的注释已经在代码里啦~ //#pragma comment(linker, "/STACK:16777216") //f ...
- Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)
题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...
- codeforces 489C.Given Length and Sum of Digits... 解题报告
题目链接:http://codeforces.com/problemset/problem/489/C 题目意思:给出 m 和 s,需要构造最大和最小的数.满足长度都为 m,每一位的数字之和等于 s. ...
随机推荐
- 按键1按下数码管显示1,按键2按下数码管显示2,按键3按下8个LED灯实现流水灯效果;
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器 #include<intrins.h> //因为要用到左右移函数,所以加入这个头文件 ...
- QA12更改使用决策时自动转至长文本并报错 上载附件 Word2007template.dotm
*&---------------------------------------------------------------------**& Report Z_SCR_WORD ...
- Excel表格数据可视化的六大常见方式,看看你都会吗?
当涉及到Excel表格数据的可视化,有许多不同的方式可以展示和呈现数据.以下是六种常见的Excel表格数据可视化方式的详细介绍. 1. 条形图(Bar Chart) 条形图是一种常见的数据可视化图表类 ...
- 【译】使用 GitHub Copilot 编写 Git 提交
在花费数小时修复 bug 或更新特性之后,我们开发人员最不愿意做的事情往往是仔细说明 Git 提交的内容.最新的 Visual Studio 预览版可以帮到您.使用新的生成 Git 提交消息特性来帮助 ...
- VideoPipe可视化视频结构化框架更新总结(2023-12-5)
项目地址:https://github.com/sherlockchou86/video_pipe_c 往期文章:https://www.cnblogs.com/xiaozhi_5638/p/1696 ...
- vue-test -------style绑定
<template> <p :style="{color:activeColor,fontSize:fontsize+'px'}"></p> & ...
- springMvc_控制台中文乱码问题
Post方法解决控制台乱码 @Override protected Filter[] getServletFilters() { CharacterEncodingFilter filter = ne ...
- 衡兰芷若成绝响,人间不见周海媚(4k修复基于PaddleGan)
一代人有一代人的经典回忆,1994年由周海媚.马景涛.叶童主演的<神雕侠侣>曾经风靡一时,周海媚所诠释的周芷若凝聚了汉水之钟灵,峨嵋之毓秀,遇雪尤清,经霜更艳,俘获万千观众,成为了一代人的 ...
- 容器网络Cilium:DualStack双栈特性分析
本文分享自华为云社区<容器网络Cilium入门系列之DualStack双栈特性分析>,作者: 可以交个朋友. 一 . 关于IPV6/IPV4 双栈 目前很多公司开始将自己的业务由ipv4切 ...
- POJ1006、hdu1370
思路:中国剩余定理.纯粹的用暴力求逆元. 1 #include<iostream> 2 #include<string.h> 3 #include<string> ...