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;
}
相关推荐
by2099912 分钟前
从 malloc/free 到 new/delete:真正理解 C++ 中的内存管理与对象生命周期
c语言·c++·经验分享·动态内存管理
额额额对了15 分钟前
SPI通信
linux·c语言·汇编·单片机·嵌入式硬件·arm
欣欣之王来了24 分钟前
AI合规专项:AI算法透明度的合规要求
人工智能·算法
wzdark25 分钟前
分块思想在算法优化中的实践与应用4
算法
Because_of_Her133 分钟前
dfs-洪水填充技巧
笔记·算法·深度优先·洪水填充
ShyanZh37 分钟前
【Python3基础】13-Python 常用设计模式
开发语言·python·设计模式
m0_3807438743 分钟前
Qt侧边栏布局的实现示例
开发语言·c++
小静AI工程实验室1 小时前
RSA 算法详解:从模幂原理到 OAEP 加密、PSS 签名与 Python 实验
python·算法
zh_xuan1 小时前
c++ 23 std::out_ptr用法
开发语言·c++23·out_ptr
xzal121 小时前
GESP Python笔记
笔记·python·算法