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;
}
相关推荐
Yingye Zhu(HPXXZYY)3 分钟前
Solution to Luogu P6340
算法
小熳芋25 分钟前
单词搜索- python-dfs&剪枝
算法·深度优先·剪枝
Bruce_Liuxiaowei35 分钟前
Nmap+Fofa 一体化信息搜集工具打造
运维·开发语言·网络·网络安全
智航GIS37 分钟前
5.1 if语句基础
开发语言·python
Xの哲學38 分钟前
Linux SLAB分配器深度解剖
linux·服务器·网络·算法·边缘计算
bu_shuo41 分钟前
MATLAB中的转置操作及其必要性
开发语言·算法·matlab
高洁011 小时前
图神经网络初探(2)
人工智能·深度学习·算法·机器学习·transformer
爱装代码的小瓶子1 小时前
算法【c++】二叉树搜索树转换成排序双向链表
c++·算法·链表
思成Codes1 小时前
数据结构:基础线段树——线段树系列(提供模板)
数据结构·算法
KoalaShane1 小时前
El-slider 增加鼠标滚动滑块事件
开发语言·前端·javascript