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 ...
随机推荐
- windows,phalcon工具的安装使用
一.使用工具之前,必须安装phalcon的扩展,也就是php_phalcon.dll动态链接库 phalcon官方地址:https://github.com/phalcon/cphalcon/rele ...
- HDOJ1242 Rescue(营救) 搜索
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 2018.09.30 bzoj2741: 【FOTILE模拟赛】L(分块+可持久化01trie)
传送门 数据结构经典题. 首先考虑另外一种询问方式. 已知权值val,在区间[1,n][1,n][1,n]中找一个数使得valvalval^a[i]a[i]a[i]最大. 这个可以直接01trie. ...
- 30. Child Labor Problem and Its Solution 童工问题及解决方法
30. Child Labor Problem and Its Solution 童工问题及解决方法 ① Over a hundred years ago,Charles Dickens shocke ...
- 第七章 介词(La préposition )
法语中的介词是将两个同类或非同类的词连接在一起,把一个句中成分同另一个句子成分联系起来,并表明两者之间关系的词类.介词是一种无词性变化的词类. ★介词的形式 ()简单形式的介词,如: ()复合形式的介 ...
- 浮点数转byte数组
; float b=34.56745f; float c=0.0; ,,,}; byte* t=fbs; float2Bytes(t,b); unsigned int addrF=(unsigned ...
- Hi,everybod,搬家了
Hi,小伙伴们,我的博客已经搬家到了GitHub,地址是:http://wxb.github.io/Blog/ 博客园以后就不维护了,有什么问题咱们GitHub上讨论啦,可以在:https://git ...
- SSH整合 第二篇 工程初建
SSH整合,第二篇. 创建工程 这里只是测试和理解hibernate.建立Java工程就好了. 1.hibernate-4.2.21.jar hibernate包下的required,即\hibern ...
- svg transform
看了这个页面的说明:http://www.2cto.com/kf/201301/186980.html 总结如下:transform包括:translate(tx,ty),scale(sx,sy),r ...
- hibernate 延迟加载深入分析(persistentSet的延迟加载)
Hibernae 的延迟加载是一个非常常用的技术,实体的集合属性默认会被延迟加载,实体所关联的实体默认也会被延迟加载.Hibernate 通过这种延迟加载来降低系统的内存开销,从而保证 Hiberna ...