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;
}
相关推荐
cui_ruicheng14 小时前
C++关联容器进阶:unordered_map / set与详解
开发语言·c++
j_xxx404_14 小时前
常见位运算基础知识,技巧总结以及力扣实战
数据结构·c++·算法·leetcode
sycmancia14 小时前
C++——C++异常处理
开发语言·c++
xxxxxxllllllshi15 小时前
java值传递和引用传递的区别?举例一些常见都笔试面试题说明,最后有速记口诀
java·开发语言
RuiBo_Qiu15 小时前
【LLM进阶-后训练&部署】1. 大语言模型全参数微调:从前向推理到反向传播的底层原理解析
人工智能·算法·语言模型·自然语言处理·ai-native
HLC++15 小时前
C++中的类和对象
开发语言·c++
子有内涵15 小时前
【Linux】程序地址空间(是什么?为什么?)
linux·运维·算法
setmoon21415 小时前
C++与量子计算模拟
开发语言·c++·算法
KIKIiiiiiiii15 小时前
微信自动化机器人开发
java·开发语言·人工智能·python·微信·自动化