Codeforces Round #277.5 (Div. 2) C Given Length and Sum of Digits...
来源:互联网 发布:数字分析推算软件 编辑:程序博客网 时间:2024/06/06 05:23
大大的传送门:就是这里
这一道卡在了特判的 1 0
本来输出 0 0
输出 -1 -1了,就错了,,
这道题就是一个恨好的贪心,往大了贪
下面是代码
#include <cstdio>#include <cstring>#include <vector>using namespace std;int n,m;int ans[110];int main(){ scanf("%d%d",&n,&m); memset(ans,0,sizeof(ans)); if(n>1&&m==0||m/n>9||m/n==9&&m%n!=0){ puts("-1 -1"); } else if(n==1&&m==0) { printf("0 0\n"); } else{ int min=m; int num=0; while(min>0){ if(min<9){ ans[num++]=min; min=0; } else{ ans[num++]=9; min-=9; } } //printf("num==%d\n",num); if(num==n){ for(int i=n-1;i>=0;i--) printf("%d",ans[i]); printf(" "); } if(num<n){ printf("1"); for(int i=1;i<n-num;i++) printf("0"); printf("%d",ans[num-1]-1); for(int i=0;i<num-1;i++) printf("9"); printf(" "); } if(num>n){ printf("-1 "); } int max=m; int cnt=0; while(cnt<n){ if(max<9&&max>0){ printf("%d",max); max=0; } else if(max>=9) { printf("9"); max-=9; } else{ printf("0"); } cnt++; } printf("\n"); } }
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...(贪心)
- 人工智能杂谈
- POJ 1062题解 Dijkstra
- 统计字母频率并排序
- POJ 1600 Centipede Collisions
- ArrayAdapter和SimpleAdapter简单使用
- Codeforces Round #277.5 (Div. 2) C Given Length and Sum of Digits...
- iOS基础框架
- 项目小技巧
- hdu4455 dp
- 蓝牙耳机现在主要有三大规格———HSP、HFP和A2DP
- linux 平台下 android studio sdk不能更新
- android:layout_weight的真实含义
- 100个房间的开关
- uva 133