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;
}
相关推荐
blurblurblun10 小时前
Go语言特性
开发语言·后端·golang
Y.O.U..10 小时前
Go 语言 IO 基石:Reader 与 Writer 接口的 “最小设计” 与实战落地
开发语言·后端·golang
qq_4308558810 小时前
线代第二章矩阵第五、六、七节矩阵的转置、方阵的行列式、方阵的伴随矩阵
线性代数·算法·矩阵
CoderCodingNo10 小时前
【GESP】C++五级真题(数论考点) luogu-B3871 [GESP202309 五级] 因数分解
开发语言·c++
jianfeng_zhu10 小时前
二叉树的中序线索化,并通过线索化后遍历二叉树
数据结构·链表
C雨后彩虹10 小时前
5G网络建设
java·数据结构·算法·华为·面试
froginwe1110 小时前
NumPy 字符串函数
开发语言
ComputerInBook10 小时前
C++编程语言:标准库:第43章——C语言标准库(Bjarne Stroustrup)
c语言·c++·c语言标准库
机器学习之心10 小时前
最小二乘支持向量机(LSSVM)结合遗传算法(GA)解决单目标优化问题,MATLAB代码
算法·支持向量机·matlab·单目标优化问题
wildlily842710 小时前
C++ Primer 第5版章节题 第九章
开发语言·c++