Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
1 second
256 megabytes
standard input
standard output
You have a positive integer m and a non-negative integer
s. Your task is to find the smallest and the largest of the numbers that have length
m and sum of digits
s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers
m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1
-1" (without the quotes).
2 15
69 96
3 0
-1 -1
贪心,考虑最大的时候把数组赋值为9,考虑最小的时候把数组第一位赋值1。其它为赋值0
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int s1[110], s2[110]; int main()
{
int m, s;
while (~scanf("%d%d", &m, &s))
{
if (s == 0 && m == 1)
{
printf("0 0\n");
continue;
}
if (m * 9 < s || s < 1) //每一位全是9都小于s,或者1.....0大于s
{
printf("-1 -1\n");
continue;
}
for (int i = 1; i <= m; ++i)
{
s1[i] = 0;
s2[i] = 9;
}
s1[1] = 1;
int dis = s - 1, cnt = m;
while (1)
{
if (9 - s1[cnt] >= dis)
{
s1[cnt] += dis;
break;
}
dis -= (9 - s1[cnt]);
s1[cnt] = 9;
cnt--;
}
for (int i = 1; i <= m; ++i)
{
printf("%d", s1[i]);
}
printf(" ");
dis = m * 9 - s;
cnt = m;
while (1)
{
if (s2[cnt] >= dis)
{
s2[cnt] -= dis;
break;
}
dis -= (s2[cnt]);
s2[cnt] = 0;
cnt--;
}
for (int i = 1; i <= m; ++i)
{
printf("%d", s2[i]);
}
printf("\n");
}
return 0;
}
Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...的更多相关文章
- Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...
- Codeforces Round #277.5 (Div. 2) ABCDF
http://codeforces.com/contest/489 Problems # Name A SwapSort standard input/output 1 s, 256 ...
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)
http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
- Codeforces Round #277.5 (Div. 2)-B. BerSU Ball
http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...
- Codeforces Round #277.5 (Div. 2)-A. SwapSort
http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...
- Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud A. SwapSort time limit per test 1 seco ...
- Codeforces Round #277.5 (Div. 2)-D
题意:求该死的菱形数目.直接枚举两端的点.平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2. 代码: #include< ...
随机推荐
- DDD领域模型数据访问权限之权限(十二)
实现权限的领域对象:BAS_Permission public partial class BAS_Permission:AggreateRoot { private IRepository<B ...
- 【AtCoder】AGC019
A - Ice Tea Store 算一下每种零售最少的钱就行,然后优先买2,零头买1 #include <bits/stdc++.h> #define fi first #define ...
- Linux dnsmasq.conf
一.配置文件:局域网内使用此dns服务时候首先会在host.dnsmasp里面找对应域名,若找不到则在resolv.dnsmasq中找 [root@operation_server dnsmasq.d ...
- Python debug 调试;
F9:执行跳到下一个断点 F8:执行下一步 F7:进入函数
- Floyd-傻子也能看懂的弗洛伊德算法(转)
暑假,小哼准备去一些城市旅游.有些城市之间有公路,有些城市之间则没有,如下图.为了节省经费以及方便计划旅程,小哼希望在出发之前知道任意两个城市之前的最短路程. ...
- Centos下基于Hadoop安装Spark(分布式)
前提 Hadoop可成功在分布式系统下启动 下载scala 链接是https://downloads.lightbend.com/scala/2.12.7/scala-2.12.7.tgz Mast ...
- 阿里云服务器配置免费https服务
过程总述 购买服务器,购买域名,备案 申请ssl证书 DNS验证 上传证书,配置nginx 很关键,打开端口!!!阿里云的443端口默认是不打开的 1.购买服务器,域名,备案 服务器我是买的阿里云的, ...
- BASH if/while/until loop
#/bin/bash ]; then counter=" counter1=" echo "for loop:" $); do echo $i done ); ...
- Metasploit AFP爆破模块afp_login
Metasploit AFP爆破模块afp_login AFP是苹果系统支持的文件服务.用户可以使用指定的账户名和密码进行远程文件管理.afp_login是一个AFP认证信息暴力破解模块.它支持对 ...
- Egret 之 消除游戏 开发 PART 6 Egret elimination game development PART 6
Egret 之 消除游戏 开发 PART 6 Egret elimination game development PART 6 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱: ...