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 ...
随机推荐
- 原生JS获取url汇总
在WEB开发中,许多开发者都比较喜欢使用javascript来获取当前url网址,本文就此为大家总结一下比较常用获取URL的javascript实现代码 URL即统一资源定位符 (Uniform Re ...
- MEME(Motif-based sequence analysis tools)使用说明
MEME(Motif-based sequence analysis tools)使用说明 2011-05-27 ~ ADMIN MEME是用于从一堆序列中搜索功能结构域的工具.比如说当你拿到了许多C ...
- 微信分享 apicloud方式 中遇到的坎
1 appid填错了. 2 图片地址没写对,可能因为拼写问题,图片不存在 3 图片大小有限制.不能太大.
- 分组取前N记录
分组取前N记录 经常看到问题,如何取出每组的前N条记录.方便大家参考于是便把常见的几种解法列出于下. 问题:有表 如下,要求取出各班前两名(允许并列第二)Table1+----+------+-- ...
- crontab误删除
命令如下: cat /var/log/cron* | grep -i "`which cron`" > ./all_temp cat ./all_temp | grep -v ...
- Linux shell脚本的字符串截取
http://blog.csdn.net/gumanren/article/details/5601544 Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.ha ...
- 解决启动nginx时报80端口被占用的问题
如何解决启动nginx时报80端口被占用 最近公司的的一个服务器上需要部署多个项目,但80端口只有一个,所有只有使用Nginx来代理,当访问域名时就可以自动 转到IP:端口号,而不需要在域名后面加端口 ...
- 2018.09.28 bzoj1563: [NOI2009]诗人小G(决策单调性优化dp)
传送门 决策单调性优化dp板子题. 感觉队列的写法比栈好写. 所谓决策单调性优化就是每次状态转移的决策都是在向前单调递增的. 所以我们用一个记录三元组(l,r,id)(l,r,id)(l,r,id)的 ...
- 2018.09.15 bzoj1977:次小生成树 Tree(次小生成树+树剖)
传送门 一道比较综合的好题. 由于是求严格的次小生成树. 我们需要维护一条路径上的最小值和次小值. 其中最小值和次小值不能相同. 由于不喜欢倍增我选择了用树链剖分维护. 代码: #include< ...
- newton法分形图
方程:z^6-1=0; %f为求解的方程,df是导数,使用的时候用funchandler定义 %res是目标分辨率,iter是循环次数,(xc,yc)是图像的中心,xoom是放大倍数 %参数视自己需求 ...