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;
}
相关推荐
佳児素花痴╮16 分钟前
树的基础知识与查找排序算法
数据结构·算法
郝学胜-神的一滴29 分钟前
Python 高级编程 026:内置数据结构之骈文纵论
开发语言·数据结构·python·程序人生·软件工程
程序员老舅7 小时前
啃透 I2C 驱动开发,才算入门嵌入式 Linux 内核驱动
数据结构·驱动开发·b树·内核·嵌入式·嵌入式开发·i2c
lueluelue477 小时前
LeetCode:链表
算法·leetcode·链表
隐积8 小时前
3.1.7.Qt容器大家族(3):QVariant——万能盒子
开发语言·qt
橘子汽水16810 小时前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
huameinan狮子10 小时前
Adaboost算法原理与计算实例
算法
别怪我很水10 小时前
API中提供了VelocityTracker类用于计算触摸事件MotionEvent的速度,而其内部默认使用的方法就是最小二乘法,本 ...
算法·gitee·最小二乘法
名字还没想好☜11 小时前
Next.js ‘use client‘ 到底加在哪:Server/Client Components 边界与常见报错
开发语言·前端·javascript·react·next.js