思路 CodeForces 835B
来源:互联网 发布:用友软件的优势 编辑:程序博客网 时间:2024/06/07 17:33
Some natural number was written on the board. Its sum of digits was not less thank. But you were distracted a bit, and someone changed this number ton, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
The first line contains integer k (1 ≤ k ≤ 109).
The second line contains integer n (1 ≤ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Print the minimum number of digits in which the initial number and n can differ.
311
1
399
0
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal ton.
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char k[100005];int b[100005];int main(){int n;scanf("%d %s",&n,k);int len = strlen(k);int sum = 0;for(int i = 0; i < len; i++){b[i] = k[i]-'0';sum = sum + b[i];}sort(b,b+len);int count = 0;if(sum >= n) { printf("0\n");return 0;}//先判断一次for(int i = 0; i < len; i++){sum = sum + 9 - b[i];count ++ ;if(sum >= n) { printf("%d\n",count); return 0;} }}
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char k[100005];int b[100005];int main(){int n;while(~scanf("%d%s",&n,k)){int len = strlen(k);int sum = 0;for(int i = 0; i < len; i++){b[i] = k[i]-'0';sum = sum + b[i];}sort(b,b+len);int count = 0;for(int i = 0; i <= len; i++)//注意要多判断一次因为是先判断再加{if(sum >= n) { printf("%d\n",count);break;} sum = sum + 9 - b[i];count ++ ;}}}
- 思路 CodeForces 835B
- codeforces 593B(思路)
- codeforces 651B Beautiful Paintings (思路题)
- CodeForces 621B B. Wet Shark and Bishops【数学+思路】
- Codeforces #332 B. Spongebob and Joke (思路)
- codeforces 608B Hamming Distance Sum 部分和+思路转换
- codeforces 589B(两次排序 + 暴力 ) (重点在于思路)
- Codeforces Round #423 (Div. 2) B. Black Square(思路)
- codeforces 839B Game of the Rows(思路题)
- Codeforces Round #438 B. Race Against Time 思路很重要
- Codeforces 835B
- codeforces 835B Key races
- codeforces 394 B. Very Beautiful Number(思路较难,优化的地方多)好题。。。
- Codeforces Round #355 (Div. 2)-B. Vanya and Food Processor,纯考思路~~
- Codeforces Round #358 (Div. 2) -- B. Alyona and Mex (思路水题)
- Codeforces Round #305 (Div. 1) B. Mike and Feet(思路)
- codeforces B
- codeforces B
- SSH 实现页面跳转
- javascript 数组去重
- Kotlin函数式编程(一) Kotlin与函数式编程
- 冒泡排序
- Linux 练习二
- 思路 CodeForces 835B
- Eclipse中.setting目录下文件介绍
- 使用 OpenSSL API 进行安全编程
- jS原型
- 吴恩达【深度学习工程师】学习笔记(九)
- python返回多个参数
- 复杂网络 初学入门资料
- MySQL 搜索语句--过滤数据
- OPENCV使用第零步 VS2017 安装 opencv3.3 及win10配置