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;
}
相关推荐
鲨莎分不晴19 小时前
【前沿技术】Offline RL 全解:当强化学习失去“试错”的权利
人工智能·算法·机器学习
刘某的Cloud20 小时前
列表、元组、字典、集合-组合数据类型
linux·开发语言·python
梁同学与Android20 小时前
Android ---【经验篇】ArrayList vs CopyOnWriteArrayList 核心区别,怎么选择?
android·java·开发语言
XFF不秃头20 小时前
力扣刷题笔记-全排列
c++·笔记·算法·leetcode
ss27320 小时前
从零实现线程池:自定义线程池的工作线程设计与实现
java·开发语言·jvm
石工记20 小时前
windows 10直接安装多个JDK
java·开发语言
菜鸟233号20 小时前
力扣669 修剪二叉搜索树 java实现
java·数据结构·算法·leetcode
郝学胜-神的一滴20 小时前
Python魔法函数一览:解锁面向对象编程的奥秘
开发语言·python·程序人生
San30.20 小时前
深入理解 JavaScript:手写 `instanceof` 及其背后的原型链原理
开发语言·javascript·ecmascript