Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
来源:互联网 发布:poi的软件 编辑:程序博客网 时间:2024/06/18 16:00
http://codeforces.com/problemset/problem/489/C
题意:给两个数N和S,让你构造一个数,这个数是N位的,且这个数的所有位之和为S,如果能构造,输出最大的和最小的数,如果不能构造,则输出-1 -1.
做法:对于最大数的构造,只要从最高位开始,能放多少就放多少,放到不能放为止。对于最小数的构造,第一位先放1,然后从最后一位开始放,注意几种特殊情况的判断。
#include <bits/stdc++.h>#define _ ios_base::sync_with_stdio(0);cin.tie(0);#define INF 0x3f3f3f3f#define eps 1e-6typedef long long LL;const double pi = acos(-1.0);const long long mod = 1e9 + 2015;using namespace std;int a[105];int b[105];int main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("int.txt","r",stdin); //freopen("out.txt","w",stdout); int N,S; cin >> N >> S; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int S1 = S; if(S == 0 && N == 1) puts("0 0"); else if(S == 0 || S > 9 * N) puts("-1 -1"); else { for(int i = 1;i <= N;i++) { if(S == 0) a[i] = 0; else { a[i] = min(9,S); S -= a[i]; } } b[1] = 1; S1 -= 1; for(int i = N;i > 0;i--) { if(S1 == 0) b[i] += 0; else { b[i] += min(9,S1); S1 -= b[i]; } } for(int i = 1;i <= N;i++) printf("%d",b[i]); printf(" "); for(int i = 1;i <= N;i++) printf("%d",a[i]); puts(""); } return 0;}
0 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...
- 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 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 - 277.5 (Div. 2)C - Given Length and Sum of Digits...(模拟 or dfs)
- codeforces#277.5 C. 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...
- Codeforces 489C. Given Length and Sum of Digits...(greedy)
- codeforces 489C Given Length and Sum of Digits...
- C. Given Length and Sum of Digits...
- Codeforces 489C - Given Length and Sum of Digits...(贪心)
- 求最大子矩阵(子矩阵无大小要求)dp
- 《Android5.1源码探究 —— ActivityManager(4):isLowRamDevice ()》
- 源码解析Android中的事件处理
- greenplum集群中 插入序列报错处理
- Window下 Python 3.4 安装ipython
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- ADF Table新增临时字段计算2个字段的和
- final的作用随着所修饰的类型而不同
- Java AIO总结与示例
- Shell脚本 变量笔记
- UNITY之SendMassage,Corouting
- 动态规划之矩阵链乘法理解
- 用java编写一个函数,统计一个字符串中每个字母出现的次数
- 构建ceph deb 安装包