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;
}
相关推荐
tryCbest9 小时前
Python 爬虫从入门到实战(二):进阶篇——反爬对抗、并发与动态页面
开发语言·爬虫·python
张祥6422889049 小时前
RTKLIB 源码解析:方差计算与高度角定权模型深度剖析
算法
-梅10 小时前
linux(番外)线程,锁,条件变量封装;日志与线程池
linux·c语言·前端·c++
S_WEAN10 小时前
【C++】STL - Priority_queue的使用及模拟实现与仿函数
开发语言·c++
电科_银尘10 小时前
【大模型算法与工程 37】语言模型强化学习基础:策略、奖励与优势
人工智能·算法·语言模型
星落梦生10 小时前
Tlias前端案例涉及知识点 (14)
开发语言·前端·javascript
FRing0321 小时前
vue2干货总结12(loading效果、全局前置导航守卫、搜索历史管理)
开发语言·前端·javascript·vue.js·vue2
wefg121 小时前
【项目】C++ 基于 Vibe Coding 的 OJ 平台
开发语言·c++
琳少_1 天前
java程序设计笔记
java·开发语言·数据库·笔记