1400*C. Given Length and Sum of Digits...(贪心)

Problem - 489C - Codeforces

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int m,s,a[110];
signed main(){
	scanf("%d%d",&m,&s);
	if(s>m*9) puts("-1 -1");
	else if(s==0&&m>1) puts("-1 -1");
	else if(s==0&&m==1) puts("0 0");
	else{
		int t=s;
		t-=1;
		a[1]=1;
		for(int i=m;i>=1;i--){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
		cout<<" ";
		t=s;
		memset(a,0,sizeof a);
		for(int i=1;i<=m;i++){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
	}
	return 0;
}
相关推荐
炸膛坦客16 分钟前
单片机/C/C++八股:(二十一)include <> 和 include ““ 的区别
c语言·c++
Yupureki24 分钟前
《Linux系统编程》12.基础IO
linux·运维·c语言·开发语言·数据库·c++
淮北49424 分钟前
bash下好用的快捷键以及linux常用指令
linux·开发语言·ubuntu·bash
炸膛坦客26 分钟前
单片机/C/C++八股:(十八)C/C++ 中 sizeof 和 strlen 的区别
c语言·c++
XiYang-DING41 分钟前
【LeetCode】LCR 019. 验证回文串 II
算法·leetcode·职场和发展
薛定谔的猫喵喵42 分钟前
卸载 Python 3.8 报错 “Could not set file security” 的终极解决方案
开发语言·python
灰色小旋风43 分钟前
力扣18 四数之和(C++)
数据结构·算法·leetcode
噜啦噜啦嘞好1 小时前
算法篇:前缀和
数据结构·算法
重生之我是Java开发战士1 小时前
【广度优先搜索】FloodFill算法: 图像渲染,岛屿数量,岛屿的最大面积,被围绕的区域
算法·宽度优先