Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
http://codeforces.com/problemset/problem/489/C
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
解题思路:构造,给你n和s表示你需要构造的数字的位数合个位数字相加的和,你需要找到满足条件的最大和最小值。最小值,从最后一位开始放数字,直到放不了,当然首位不能为零。最大值,从头开始放,没什么要注意的- -。
1 #include <stdio.h>
2 #include <iostream>
3 #include <string.h>
4 #include <stdlib.h>
5
6 const int maxn = ;
7
8 int a[maxn], b[maxn], m, s;
9
void solve(){
int cnt1, cnt2, temp1, temp2;
int i;
//特判
if(m == && s == ){
printf("0 0\n"); return ;
}
//无法构造的情况
if(s > m * || (m > && s == )){
printf("-1 -1\n"); return ;
}
memset(a, , sizeof(a));
memset(b, , sizeof(b));
temp1 = s; cnt1 = ;
a[m - ] = ; temp1--;
for(i = ; i < m - ; i++){
a[i] = ;
}
while(temp1 > ){
a[cnt1++] = ;
temp1 -= ;
}
if(temp1 > ){
a[cnt1] = a[cnt1] + temp1;
cnt1++;
}
temp2 = s; cnt2 = ;
while(temp2 > ){
b[cnt2++] = ;
temp2 -= ;
}
if(temp2 > ){
b[cnt2++] = temp2;
}
while(cnt2 < m){
b[cnt2++] = ;
}
for(i = m - ; i >= ; i--){
printf("%d", a[i]);
}
printf(" ");
for(i = ; i < cnt2; i++){
printf("%d", b[i]);
}
printf("\n");
}
int main(){
while(scanf("%d %d", &m, &s) != EOF){
solve();
}
return ;
62 }
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...
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- 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< ...
随机推荐
- E20181216-hm
intersect vt. (指线条.道路等) 相交,交叉; vt. 横断,横切,横穿;
- 萌新笔记之二叉搜索树(BST)
前言,以前搞过线段树,二叉树觉得也就那样= =.然后数据结构的课也没怎么听过,然后下周期中考... 本来以为今天英语考完可以好好搞ACM了,然后这个数据结构期中考感觉会丢人,还是好好学习一波. 二叉搜 ...
- CodeForces660B【模拟—水】
感觉模拟题用函数分块写比较清晰~传参的话,字符串要么直接全局,或者指针也是容易操作,总之思路清晰,然后分块清晰,模拟wa的少吧. 这题水题,不说了. #include <bits/stdc++. ...
- unity5之代码创建状态机,玩的666
http://blog.csdn.net/litaog00/article/details/50483189 最近做项目的时候用到了状态机,网上搜了一下帖子,大部分都是简单介绍使用方法的,讲解的详细的 ...
- [Xcode 实际操作]二、视图与手势-(1)UIView视图的基本使用
目录:[Swift]Xcode实际操作 本文将演示在视图控制器的根视图里添加两个视图对象. import UIKit class ViewController: UIViewController { ...
- 如何在Linux服务器上部署禅道
最近换了新的项目团队,由于新团队比较年轻化,没有实行正规的项目管理,于是我自告奋勇要为团队管理出一份力,帮助团队建立敏捷化的项目管理,经过多方考究和对比后,选择了目前较受欢迎的开源项目管理软件:禅道. ...
- 基于 Laravel 开发 ThinkSNS+ 中前端的抉择(webpack/Vue)踩坑日记
在上一篇文章< ThinkSNS+基于Laravel master分支,从1到 0,再到0.1>,简单的介绍了 ThinkSNS+ ,这里分享在开发过程中,前端选择的心理活动. Larav ...
- 笔记-JavaWeb学习之旅12
会话技术 Cookie:客户端会话技术,将数据保存到客户端 package com.data.Cookie; import javax.servlet.ServletException; import ...
- adb server version (39) doesn't match this client (40); killing...
在启动RN项目的时候也报错,上面的错误是在adb的环境变量中的位置和android studio的sdk不是一个位置.adb是在sdk中的,所以他们应该是一致的位置 android studio的sd ...
- swift SqliteDB使用
操作步骤: 1,在 Build Phases -> Link Binary With Libraries 中点击加号,添加 libsqlite3.0.tbd 到项目中来 2,创建连接头文件B ...