CodeForces-489C Given Length and Sum of Digits...
来源:互联网 发布:java中的设计模式ppt 编辑:程序博客网 时间:2024/06/08 19:45
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int m_max = 100 + 5;int m, s, sum;int digit[m_max];int digit_max[m_max];bool flag;int main(){ while(~scanf("%d %d", & m, & s)) { if(m == 1 && s == 0) { printf("0 0\n"); continue; } memset(digit, 0, sizeof(digit)); digit[0] = 1; sum = 1; flag = false; for(int i = 0; i < m; i ++) { while(digit[i] < 9) { if(sum < s) { digit[i] ++; sum ++; } if(sum == s) { flag = true; goto End; } if(sum > s) goto End; } } End: if(flag) { for(int i = 0; i < m; i ++) digit_max[i] = digit[i]; if(!digit[m - 1]) { digit[m - 1] = 1; for(int i = m - 2; i >= 0; i --) { if(digit[i]) { digit[i] --; break; } } } for(int i = m - 1; i >= 0; i --) printf("%d", digit[i]); printf(" "); for(int i = 0; i < m; i ++) printf("%d", digit_max[i]); printf("\n"); } else printf("-1 -1\n"); } return 0;}
题目:
输入m, s。m代表数字的位数,s代表各个位上的数字要求和为s。求满足要求的最小值和最大值。没有输出-1 -1。
题解:
水题。本来想偷工减料点,结果越写越麻烦,BUG百出。也懒得从头改了。
0 0
- 【Codeforces】 489C Given Length and Sum of Digits
- CodeForces 489C Given Length and Sum of Digits...
- Codeforces 489C Given Length and Sum of Digits
- CodeForces-489C Given Length and Sum of Digits...
- Codeforces-489C-Given Length and Sum of Digits...
- Codeforces 489C. Given Length and Sum of Digits...(greedy)
- codeforces 489C Given Length and Sum of Digits...
- codeforces#277.5 C. Given Length and Sum of Digits
- C. Given Length and Sum of Digits...
- CF 489C Given Length and Sum of Digits... 贪心
- Codeforces 489C - Given Length and Sum of Digits...(贪心)
- 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...
- Codeforces #277.5 (Div. 2) C. Given Length and Sum of Digits...(简单贪心)
- 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...
- Codeforces - 277.5 (Div. 2)C - Given Length and Sum of Digits...(模拟 or dfs)
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- Android 圆角带边框的Button
- ubuntu安装ghc遇到的问题 缺少编译库libgmp.so.3: cannot open shared object file: No such file解决方案
- oracle 多表关联更新,需要更新的字段在另一个表里
- 跳槽季:分享从事C#开发人员面试经验
- Android 平台下使用 i2c-tools
- CodeForces-489C Given Length and Sum of Digits...
- OC部分知识点(2)
- UITableViewCell复用后,label上的字重叠的问题
- 算法
- android图形图像处理PorterDuffXfermode
- redis的启动与停止 可执行文件
- WebService 功能测试
- 项目构建工具Maven的学习笔记
- relocation error: /usr/lib/libswresample.so.1: symbol av_calloc, version LIBAVUTIL_54 not defined i