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;
}
相关推荐
foundbug99920 分钟前
自适应滤除直达波干扰的MATLAB实现
开发语言·算法·matlab
XDH_CS24 分钟前
MySQL 8.0 安装与 MySQL Workbench 使用全流程(超详细教程)
开发语言·数据库·mysql
小短腿的代码世界43 分钟前
Qt实时盈亏计算深度解析:从持仓数据到动态盈亏展示
开发语言·qt
MegaDataFlowers1 小时前
206.反转链表
数据结构·链表
小康小小涵1 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python
lzjava20241 小时前
Python的函数
开发语言·python
Awesome Baron2 小时前
skill、tool calling、MCP区别
开发语言·人工智能·python
爱编码的小八嘎2 小时前
C语言完美演绎9-12
c语言
Python私教2 小时前
GenericAgent PySide6 桌面应用深度解析:悬浮按钮 + 聊天面板的原生 Qt 方案
开发语言·数据库·qt
矢志航天的阿洪2 小时前
用 MATLAB 控制 STK Aviator:从零搭建一个 AWACS 支援作战场景
开发语言·matlab