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 ...
随机推荐
- Shell编程实例
一.简介 从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更 ...
- sdk接入
文档 http://blog.csdn.net/chenjie19891104/article/details/42217281 视频: https://chuanke.baidu.com/v2869 ...
- Nginx详解(正向代理、反向代理、负载均衡原理)
Nginx配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行 ...
- 20155328 2016-2017-2 《Java程序设计》第7周学习总结
20155328 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 时区 Date与DateFormat Date只用来获取epoch毫秒数 DateForma ...
- 2018.10.02 NOIP模拟 矩阵分组(二分答案)
传送门 考场上并不会写二分的check函数,下来看了看题解发现真是妙极. 不难想到每次直接从四个角各按阶梯状拓展出合法区域A,再检验B是否合法就行了.(然而考场上写的弃疗了) 于是题解用了一些小技巧优 ...
- [GO]解决golang.org/x/ 下包下载不下来的问题
因为在项目中要使用到一个golang.org的包,但是因为墙的问题,官方方法已经无法使用,但是在github上存在一个镜像站可以使用,我们只需要将它克隆下来就可以正常使用了 mkdir -p $GOP ...
- java拷贝文件到另一个目录下
package com.util; import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream ...
- HDU 2546 饭卡 (01背包问题)
题意:中文的吧,飘过~ 析:学过DP的都应该感觉到是动态规划吧,就是一个01背包问题,不同的是,这个题又加入一些新的条件,就是不满5元不能消费,过了5元即使超了也行(这个学校真不错,都可以预支),最后 ...
- 9) 依赖查询 & 镜像站
依赖查询 http://mvnrepository.com/ Maven仓库查询 http://search.maven.org 仓库 加上这两个,如果使用中央仓库 Eclipse 极有可能会卡死 & ...
- POI解析Excel文件
@Test public void test1() throws FileNotFoundException, IOException{ HSSFWorkbook workbook = new HSS ...