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;
}
相关推荐
每天要多喝水12 小时前
动态规划Day30:买卖股票
算法·动态规划
v_for_van12 小时前
力扣刷题记录6(无算法背景,纯C语言)
c语言·算法·leetcode
之歆12 小时前
HA 高可用集群指南
java·开发语言
-To be number.wan12 小时前
算法学习日记 | 双指针
c++·学习·算法
爱编码的小八嘎13 小时前
第2章 认识CPU-2.3 32位微处理器(1)
c语言
lsx20240613 小时前
电子商务网站主机:选择与维护指南
开发语言
样例过了就是过了13 小时前
LeetCode热题100 最大子数组和
数据结构·算法·leetcode
wangluoqi13 小时前
c++ 逆元 小总结
开发语言·c++
BackCatK Chen13 小时前
第十五章 吃透C语言结构与数据形式:struct/union/typedef全解析
c语言·开发语言·数据结构·typedef·结构体·函数指针·联合体
瓦特what?13 小时前
插 入 排 序
开发语言·c++