Codeforces-The number on the board
来源:互联网 发布:java接口日志 编辑:程序博客网 时间:2024/05/17 05:52
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, 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.
Examples
input
3
11
output
1
input
3
99
output
0
Note
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 to n.
题意:给你两个数k和n,将n所有位上的数加起来,判断是否大于k,若大于或等于k,则输出0,若不大于
k,则输出最少要改变n的几位数,才能使n所有位数字加和不小于k
思路:很简单,若果改变,肯定是改变一个最小的数,让它变为9.
#include <iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>using namespace std;#define ll long longconst int max1=1e5+10;int cmp(int x,int y){ return x>y;}int main(){ ll k,sum,len,sumfen,i; char s[max1],h[max1]; while(~scanf("%lld",&k)) { sum=0; getchar(); gets(s); len=strlen(s); for(i=0;i<len;i++) { sum+=s[i]-'0'; h[i]=9-(s[i]-'0'); } sort(h,h+len,cmp); sumfen=0; if(sum>=k) { printf("0\n"); } else { for(i=0;i<len;i++) { sumfen+=h[i]; if(sumfen+sum>=k) { printf("%lld\n",i+1); break; } } } } return 0;}
- Codeforces-The number on the board
- codeforces B. The number on the board
- The number on the board
- The number on the board
- Codeforces 835B-The number on the board
- Codeforces #835B: The Number on the Board 题解
- Codeforces 835 B The number on the board
- (贪心)Codeforces Round #427 B. The number on the board
- Codeforces 835 B The number on the board
- CodeForces 835B The number on the board
- codeforces 835b The number on the board
- CodeForces 835 B.The number on the board(贪心)
- codeforces 835B The number on the board
- Codeforces 835B The number on the board (贪心)
- codeforces 835b 之 The number on the board
- codeforces 835B The number on the board
- CF835B-The number on the board
- Codeforces835B The number on the board
- 获取两个日期相差的年数月数天数(年@月@天)
- 字符串转换成数字
- 《intellij idea学习经历》-03- intellij idea如何安装scala插件
- H.264中NALU、RBSP、SODB的关系 (弄清码流结构)
- 在JS中,字符串连接数字,数字会被自动转换成字符串
- Codeforces-The number on the board
- 如何提高网站速度
- STL之map简单应用之回文串
- 广田集团——建安装饰行业BI标杆客户
- Linux命令date日期时间和Unix时间戳互转
- JS中({})和(){}的区别
- POI之You can define up to 4000 styles in a .xls workbook-yellowcong
- jQuery(全选/反选)与每个选项的联动
- LeetCode——461. Hamming Distance(C++,模拟)