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;
}
相关推荐
平凡但不平庸的码农8 小时前
Go 语言:值传递 vs 指针传递
开发语言·后端·golang
神仙别闹8 小时前
基于Python实现一个C语言的编译器
java·c语言·python
Allen_LVyingbo8 小时前
面向医疗群体智能的协同诊疗与群体决策支持系统(下)
开发语言·数据结构·windows·python·动态规划
读书札记20228 小时前
Qt Creator 调试报错:Unable to create a debugging engine.
开发语言·qt
透明的玻璃杯8 小时前
Qt Creator + Windows + Protobuf 最优方案(Mqqt通讯采用的方式)
开发语言·windows·qt
玛卡巴卡ldf8 小时前
【LeetCode 手撕算法】(回溯)全排列DFS、子集、电话号码字母组合 九键、组合总和、括号生成、单词搜索、分割回文数
java·算法·leetcode·力扣
小书房8 小时前
Kotlin协程的运行原理
android·开发语言·kotlin·协程
隐退山林8 小时前
JavaEE进阶:SpringIoC&DI
java·开发语言·java-ee
水煮白菜王8 小时前
Claude Code 全方位使用手册
java·开发语言·网络
Highcharts.js8 小时前
金融Web App中的复杂时序数据可视化:从选型到高性能实践
开发语言·金融·highcharts·实战代码·响应式图表