Codeforces Round #427 (Div. 2) B. The number on the board
引子:
A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会....
B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更好一点...
C题WA第9组,GG思密达....明天起床再补C吧 - -
题目链接:
http://codeforces.com/contest/835/problem/B
B. The number on the board
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.
Input
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.
Output
Print the minimum number of digits in which the initial number and n can differ.
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.
解题思路:
由于题目过短题意就不说了,其实,具体思路看代码吧!
AC代码:
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <string.h>
#include <iostream>
#include<algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include<string>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1e5+;
#define lrt (rt*2)
#define rrt (rt*2+1)
#define LL long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define exp 1e-8
#define For(i,n) for(int i=0;i<n;i++)
//************************************************63
char a[maxn];
LL b[maxn];
int main()
{
LL n,sum=,k=,ans=;
scanf("%I64d %s",&n,a);
for(LL i=;a[i]!='\0';i++)
{
b[k]=a[i]-'';
sum+=b[k];
k++;
}
sort(b,b+k);
while(sum<n)
{
sum+=(-b[ans]);
ans++;
}
cout<<ans<<endl;
return ;
}
Codeforces Round #427 (Div. 2) B. The number on the board的更多相关文章
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #427 (Div. 2)
B. The number on the board 题意: 有一个数字,它的每个数位上的数字的和不小于等于k.现在他改变了若干位,变成了一个新的数n,问现在的数和原来的数最多有多少位不同. 思路: ...
- Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心
Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...
- 【Codeforces Round #427 (Div. 2) B】The number on the board
[Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)
Two boys decided to compete in text typing on the site "Key races". During the competition ...
随机推荐
- Scrum 项目3.0--软件工程
1. 确保product backlog井然有序.(参考示例图1) (例图1) 2.把故事进一步拆分成任务.(参考示例图2) (例图2) 3. 形成Sprint backlog. Scrum mast ...
- bzr: ERROR: These branches have diverged. Use the missing command to see how.
这个错误是在提交之后执行bzr pull时出现的,先uncommit,再pull就可以了.
- 深入浅出 JMS(三) - ActiveMQ 消息传输
深入浅出 JMS(三) - ActiveMQ 消息传输 一.消息协商器(Message Broker) broke:消息的交换器,就是对消息进行管理的容器.ActiveMQ 可以创建多个 Broker ...
- Mina 系列(二)之基础
Mina 系列(二)之基础 Mina 使用起来多么简洁方便呀,就是不具备 Java NIO 的基础,只要了解 Mina 常用的 API,就可以灵活使用并完成应用开发. 1. Mina 概述 首先,看 ...
- oracle建存储过程
进入plsql命令行 [10:42:10 liuyi@localhost]/home/liuyi>sqlplus demo/demo@180.200.3.129/meboss 连接串格式:用户名 ...
- fastjson解析List对象
List<String[]> body = JSON.parseObject(msg.getBody().toString(), new TypeToken<List<Stri ...
- activemq.bat 在window7 x64下启动(安装)报错解决方案
在启动 apache-activemq-5.15.2/activemq.bat 时候报错,提示以下信息: wrapper | --> Wrapper Started as Consolewr ...
- 2018.09.28 牛客网contest/197/B面积并(二分+简单计算几何)
传送门 比赛的时候把题目看成求面积交了,一直没调出来. 下来发现是面积并气的吐血. 码了一波发现要开long double. 然而直接用现成的三角函数会挂. 因此需要自己手写二分求角度. 大致思路就是 ...
- linxu ssh 双端认证 不成功之authorized_keys
linxu ssh 双端认证 不成功之authorized_keys liunx双端认证可以让我们更简便的在两台服务器之间传输文件,配置暂且不说,网上有大部分的文章可以搜索到,今天我要说的是在不成功的 ...
- 继承方法-->原型的相互引用
function Father(){} Father.prototype.name = 'zhang'; function Son(){} function inherit(Target,Orgin) ...