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;
}
相关推荐
y = xⁿ1 分钟前
【LeetCode】哈希表
算法·leetcode·散列表
时寒的笔记2 分钟前
js7逆向案例_禁止f12打开&sojson打开
开发语言·javascript·ecmascript
大鹏说大话6 分钟前
什么是“过早优化”?
开发语言
码云数智-园园7 分钟前
RESTful API vs GraphQL:设计哲学、性能博弈与选型指南
开发语言
智者知已应修善业8 分钟前
【51单片机独立按键控制数码管动态显示和LED间隔闪烁并清零】2023-5-28
c语言·经验分享·笔记·算法·51单片机
每天吃饭的羊15 分钟前
nest,java对比
java·开发语言
sycmancia15 分钟前
Qt——登录对话框
开发语言·qt
专注VB编程开发20年15 分钟前
WebView2同时执行多个Promise异步任务性能损失1毫秒以内
开发语言
froginwe1116 分钟前
Perl 目录操作指南
开发语言