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;
}
相关推荐
Tisfy11 分钟前
LeetCode 3561.移除相邻字符:栈(相邻相消)
算法·leetcode·字符串·题解·栈·相邻相消
战61714 分钟前
Python 基础算法:三种排序、二分查找与递归
开发语言·python·算法
羊在吃青草42 分钟前
C语言之数组
c语言·数据结构
郝学胜-神的一滴1 小时前
量化交易从入门到精通 05:策略从哪来
开发语言·python·numpy·pandas·scikit-learn·matplotlib·scipy
灯澜忆梦1 小时前
并查集(Disjoint Set Union,DSU)
数据结构·算法
烟烟Abandon1 小时前
FFmpeg开发基础之 C 语言中的文件操作
c语言·ffmpeg
zbguolei1 小时前
第001篇 · 算盘与差分机
开发语言·php
专注仿真1 小时前
达梦数据库 SQL 优化实战:从执行计划到索引、统计信息与参数调优
数据结构·数据库·数据库开发·数据库架构
Shaoshing2 小时前
LeetCode100 155.最小栈
java·数据结构·算法