题目链接:http://codeforces.com/contest/835/problem/B

题意:给定一个数k和一个数字串n。问你最少改几个数字才能满足所有数字的和不小于k。

思路:考虑贪心,每次肯定把最小的数字改成'9' 会使得所有数字的和最大。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
const int INF = 1e9;
const int mod = 1e9 + ;
char n[MAXN];
int main(){
#ifdef kirito
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int k;
while (~scanf("%d", &k)){
scanf("%s", n);
int sum = ,len=strlen(n),res=;
for (int i = ; i < len; i++){
sum += (n[i] - '');
}
sort(n, n + len);
for (int i = ; i < len&&sum<k; i++,res++){
sum = (sum - (n[i] - '') + );
}
printf("%d\n", res);
}
return ;
}

Codeforces Round #427 (Div. 2) - B的更多相关文章

  1. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  2. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  7. Codeforces Round #427 (Div. 2)—A,B,C,D题

    A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...

  8. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

  9. 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics

    [Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...

  10. 【Codeforces Round #427 (Div. 2) A】Key races

    [Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...

随机推荐

  1. CentOS 7 安装wps2019

    1. download https://www.wps.cn/product/wpslinux 2. rpm 安装缺少lib包,于是yum 安装 .x86_64.rpm 3.安装完成,运行的时候又报错 ...

  2. 使用node.js搭建本地服务器

    第一步安装node:https://nodejs.org/zh-cn/download/ 接下来就需要安装http的镜像文件 打开cmd:输入以下命令 npm install http-server ...

  3. git强行覆盖master分支

    目录 我遇到的场景 需要注意的预备操作 操作步骤 我遇到的场景 1.master分支只为护较早的版本 2.由于业务不稳定,新业务和功能都在dev 分支上,dev的开发周期很长,一直变更迭代 3.从de ...

  4. JavaScript 文件拖拽上传插件 dropzone.js 介绍

    http://www.renfei.org/blog/dropzone-js-introduction.html

  5. AI工程师职业规划和学习路线完整版

    AI工程师职业规划和学习路线完整版   如何成为一名机器学习算法工程师 成为一名合格的开发工程师不是一件简单的事情,需要掌握从开发到调试到优化等一系列能 力,这些能力中的每一项掌握起来都需要足够的努力 ...

  6. Base64工具类并发问题!

    为减少对象创建次数,一般会做如下编码: public class EncodeUtils { private static BASE64Encoder encoder; private static ...

  7. sed扩展命令使用

    [root@b ~]# cat f.txt inet addr:192.168.0.110 Bcast:192.168.0.255 Mask:255.255.255.0[root@b ~]# cat ...

  8. url的匹配问题

    1.例如我当前访问的路径是 127.0.0.1:8000/app01/customer/ 此时我需要在这个界面跳转另外一个界面127.0.0.1:8000/app02/books/,于是我定义一个a标 ...

  9. 移动端自动化==>Appium定位方式总结

    1.ID Android Android的resource-id对应ID定位方式,可以通过index来获取需要的元素(从0开始查找dom树中的同名resource-id属性).使用appium-des ...

  10. Spring MVC 中RequestContextHolder获取request和response

    1.最简单方式:处理方法入参 例如: @RequestMapping("/test") @ResponseBody public void saveTest(HttpServlet ...