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;
}
相关推荐
紫金修道3 分钟前
【DeepAgent】概述
开发语言·数据库·python
Via_Neo6 分钟前
JAVA中以2为底的对数表示方式
java·开发语言
书到用时方恨少!11 分钟前
Python multiprocessing 使用指南:突破 GIL 束缚的并行计算利器
开发语言·python·并行·多进程
cch891815 分钟前
PHP五大后台框架横向对比
开发语言·php
天真萌泪1 小时前
JS逆向自用
开发语言·javascript·ecmascript
野生技术架构师1 小时前
一线大厂Java面试八股文全栈通关手册(含源码级详解)
java·开发语言·面试
袋鼠云数栈1 小时前
集团数字化统战实战:统一数据门户与全业态监管体系构建
大数据·数据结构·人工智能·多模态
Q一件事2 小时前
R语言制图-相关性及关系网络图
开发语言·r语言
坊钰2 小时前
Java 死锁问题及其解决方案
java·开发语言·数据库
小月球~2 小时前
天梯赛 · 并查集
数据结构·算法