}strings1,s2;for(inti=0;i<m;i++){intx=min(9,s); s-=x; s2+=char(x+'0'); } s1=s2; reverse(s1.begin(),s1.end());boolok=true;for(inti=0;i<m&&ok;i++){if(s1[i]=='0'){for(intj=i+1;j<m&&ok;j++){if(s1[j]!='0'){ s1[j]--; s1[i]++; ok=false;break;...
这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大。 所以写一个can(int m, int s)函数,来判断是否存在一个m位数其各位数字之和为s 这里先不考虑前导0的事,代码看起来可能是这个样子的: boolcan(intm,ints) {return(s >=0&& s <= m*9); } 比如我们现在要求满足要求的最小整数,从最...
查看题目 登录后递交 讨论 题解 文件 统计 ID 5693 时间 1000ms 内存 256MiB 难度 (无) 标签 dp greedy implementation *1400 递交数 0 已通过 0 上传者 root
CodeForces 489C (贪心) Given Length and Sum of Digits...,题意:找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的。分析:这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大。所以写一个can(intm,ints)函数,来
You have a positive integermand a non-negative integers. Your task is to find the smallest and the largest of the numbers that have lengthmand sum of digitss. The required numbers should be non-negative integers written in the decimal base without leading zeroes. ...
You have a positive integermand a non-negative integers. Your task is to find the smallest and the largest of the numbers that have lengthmand sum of digitss. The required numbers should be non-negative integers written in the decimal base without leading zeroes. ...
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. Input The single...
You have a positive integermand a non-negative integers. Your task is to find the smallest and the largest of the numbers that have lengthmand sum of digitss. The required numbers should be non-negative integers written in the decimal base without leading zeroes. ...
You have a positive integermand a non-negative integers. Your task is to find the smallest and the largest of the numbers that have lengthmand sum of digitss. The required numbers should be non-negative integers written in the decimal base without leading zeroes. ...
题目链接:http://codeforces.com/problemset/problem/489/C 题目意思:给出 m 和 s,需要构造最大和最小的数。满足长度都为 m,每一位的数字之和等于 s。如果构造不出来,输出 -1 -1。否则输出最小和最大且符合条件的数。 想了两个多小时,发现想错了方向... /**...