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;
}
相关推荐
Navigator_Z6 小时前
LeetCode //C - 1275. Find Winner on a Tic Tac Toe Game
c语言·算法·leetcode
未来之窗软件服务6 小时前
递归时间复杂度演算T (n)=aT (n/b)+f (n)-东方仙盟
算法·仙盟创梦ide·东方仙盟
丹宇码农6 小时前
Go 与 Python 协程(Coroutine)对比演示项目
开发语言·python·golang
ttwuai7 小时前
Go开源后台管理系统推荐:3个官方仓库怎么按技术栈和适用边界比较?
开发语言·golang·开源
垆边人似月.7 小时前
华为机考题:明明的随机数
数据结构·算法·华为
Doubbbbbbble云7 小时前
多维空间索引结构R树与KD树性能对比研究4
算法
海上小飞龙7 小时前
【KMP算法-中篇】next 数组的递推:往前填一位,靠的是往回退几步
算法
lusklusklusk7 小时前
Python 四大数据结构详解:元组、列表、集合、字典的特点与增删改查
数据结构·windows·python
keyipatience7 小时前
B树详解:从零构建平衡多路搜索树
数据结构·b树·算法·图搜索
个 人 练 习 生7 小时前
C++-----string基本使用详解
开发语言·c++·学习