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;
}
相关推荐
清酒难咽5 小时前
算法案例之递归
c++·经验分享·算法
Rabbit_QL5 小时前
【水印添加工具】从零设计一个工程级 Python 图片水印工具:WaterMask 架构与实现
开发语言·python
天“码”行空6 小时前
简化Lambda——方法引用
java·开发语言
让我上个超影吧6 小时前
【力扣26&80】删除有序数组中的重复项
算法·leetcode
z20348315206 小时前
C++对象布局
开发语言·c++
Beginner x_u6 小时前
如何解释JavaScript 中 this 的值?
开发语言·前端·javascript·this 指针
java1234_小锋7 小时前
Java线程之间是如何通信的?
java·开发语言
张张努力变强7 小时前
C++ Date日期类的设计与实现全解析
java·开发语言·c++·算法
沉默-_-7 小时前
力扣hot100滑动窗口(C++)
数据结构·c++·学习·算法·滑动窗口
钱彬 (Qian Bin)7 小时前
项目实践19—全球证件智能识别系统(优化检索算法:从MobileNet转EfficientNet)
算法·全球证件识别