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

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

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

  1. #define _CRT_SECURE_NO_DEPRECATE
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<string>
  7. #include<queue>
  8. #include<vector>
  9. #include<time.h>
  10. #include<cmath>
  11. #include<set>
  12. #include<map>
  13. using namespace std;
  14. typedef long long int LL;
  15. const int MAXN = + ;
  16. const int INF = 1e9;
  17. const int mod = 1e9 + ;
  18. char n[MAXN];
  19. int main(){
  20. #ifdef kirito
  21. freopen("in.txt", "r", stdin);
  22. freopen("out.txt", "w", stdout);
  23. #endif
  24. int k;
  25. while (~scanf("%d", &k)){
  26. scanf("%s", n);
  27. int sum = ,len=strlen(n),res=;
  28. for (int i = ; i < len; i++){
  29. sum += (n[i] - '');
  30. }
  31. sort(n, n + len);
  32. for (int i = ; i < len&&sum<k; i++,res++){
  33. sum = (sum - (n[i] - '') + );
  34. }
  35. printf("%d\n", res);
  36. }
  37. return ;
  38. }

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. 安装mariadb报错: Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

    卸载和删除都使用过了,没有起到效果,然后用了如下的方案,进行解决: CentOS 从 Yum 源安装配置 Mariadb 2017.03.01 WangYan 学习笔记  热度 7℃ 一.安装 Mar ...

  2. Java之Integer类

    Integer类简介: Integer类是基本数据类型int的包装器类,是抽象类Number的子类,位于java.lang包中. Integer类在对象中包装了一个基本类型int的值,也就是每个Int ...

  3. zabbix 监控hp 打印机

    https://share.zabbix.com/search?searchword=hp+printer&search_cat=1

  4. 自动化运维--ansible(2)

    问题一:如何在多台服务器中配置Web项目上线的所有环境 解答: 1.使用ansible配置nginx服务 在安装前了解rpm与yum的区别  rpm是压缩包安装依赖包需要自己手动安装,yum安装解决依 ...

  5. OpenStack 实现技术分解 (6) 通用库 — oslo_log

    目录 目录 前文列表 扩展阅读 日志级别 oslolog 初始化设置 DEMO oslolog 的相关配置项 oslolog 的日志级别 oslolog 的使用技巧 推荐使用 LOGdebug 的地方 ...

  6. What is the difference between a URI, a URL and a URN?

    资料: URI: URL: URN:

  7. Jmeter之保存响应到文件

    在jmeter中使用保存响应到文件 ------适用于非GUI模式执行脚本时,无法查看报错的信息. 1.添加组件: 2.各个配置项说明: (1.名称:即组件在整个测试计划中的名称显示,建议设置为用意义 ...

  8. dcef3 指出一个坑

    dcef3 指出一个坑 http://ju.outofmemory.cn/entry/80119 BccSafe's Blog 2014-06-11 2388 阅读   dcef3提供了TChromi ...

  9. ABAP基本数据类型

    ABAP 程序中共包含8种基本数据类型: 数据类型名称 描述 属  性 C Character Text(字符类型) 默认长度=1,默认值=blank,最大长度无限制 N Numeric Text(数 ...

  10. node-webkit-updater——NW.js自动更新

    NW.js自动更新三种方案: 1)node-webkit-updater(推荐) 2)nwjs-autoupdater 3)nw-autoupdater NW.js自动更新三种方案:[http://d ...