Codeforces 835B
来源:互联网 发布:江苏远洋数据 编辑:程序博客网 时间:2024/06/05 22:47
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.
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 to n.
思路:这题在比赛时一直wa,完全找不出错误,第二天听人一讲题意,原来这题要求的是要变得最少的个数,而不是最小的位数。
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <cmath>#include <queue>#include <map>#include <algorithm>#include <stdlib.h>using namespace std;#define ma(a) memset(a,0,sizeof(a))#define ll long longint main(){ ll k; while(cin>>k) { char n[111111]; cin>>n; int len=strlen(n); sort(n,n+len); ll sum=0; int i; for(i=0;i<len;i++) { sum+=n[i]-'0'; } if(sum>=k) { cout<<0<<endl; continue; } ll z=0; for(i=0;i<len;i++) { if(sum<k)z++; else break; sum=sum+9-(n[i]-'0'); } cout<<z<<endl; } return 0;}
- Codeforces 835B
- 思路 CodeForces 835B
- codeforces 835B Key races
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- codeforces 214B Hometask
- Google Guava简介
- lnk2019无法解析的外部命令
- tostring/tonumber的使用
- 设计模式之工厂模式
- 应用jquery操作元素样式(一)
- Codeforces 835B
- ADB命令
- +、-、*、/、%的使用
- 前缀和--分布函数--cf835c star sky
- Oracle之多表查询
- HDU 6045 Is Derek lying?【】
- Hive基础到高级
- ==、~=、>、<、<=的使用
- 7月31日云栖精选夜读:金融安全资讯精选 2017年第一期:云战略下的安全思维转型与新认知