把所有字符串上的数字加起来,看是否超过k,没有超过k的话,把字符串sort,从第一位开始,将字符变成9,直到sum大于等于k为止。

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>using namespace std;typedef long long ll;int main ()
{int i,k,cnt,sum;string s;cin >> k;cin >> s;i  = 0;sum = 0;while(i<s.length()){sum += (s[i]-'0');i++;}if(sum>=k){cout << "0" << endl;}else{i = 0;cnt = 0;sort(s.begin(),s.end());while(i<s.length()){sum += (9-(s[i]-'0'));i++;cnt++;if(sum>=k)break;}cout << cnt << endl;}return 0;
}

【Codeforces】835B The number on the board (贪心)相关推荐

  1. codeforces#324(div2) E. Anton and Ira 贪心

    codeforces#324(div2) E. Anton and Ira  贪心 E. Anton and Ira time limit per test 1 second memory limit ...

  2. CodeForces 991E Bus Number DFS+ 组合数

    CodeForces 991E Bus Number DFS+ 组合数 题目大意:给定一个数字,数字里出现的每一个数,都至少要用一个,问能组成多少个新数,不加前导零. input: 2028 outp ...

  3. Codeforces Round #774 (Div. 2) Power Board(数学)

    Codeforces Round #774 (Div. 2) Power Board(数学) 链接 题意:给一个n*m的矩阵,每个元素的值是 i j i^j ij,问有多少个不一样的元素 思路:不过这 ...

  4. Codeforces Beta Round #11 A. Increasing Sequence 贪心

    A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...

  5. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  6. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  7. 【Codeforces - 864D】Make a Permutation!(贪心,字典序)

    题干: Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Rece ...

  8. 【CodeForces - 349B】Color the Fence (贪心,填数)

    题干: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on th ...

  9. 【CodeForces - 589F】Gourmet and Banquet (贪心,思维,二分)

    题干: A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet ...

最新文章

  1. Clojure程序设计
  2. accessid管理_Access班级管理的使用方法
  3. OpenCV学习:Mat结构中的数据共享机制
  4. opencv 显示图片(直接)
  5. 哲学家就餐问题php代码,Python实现哲学家就餐问题实例代码
  6. ASP.NET Core中的分布式缓存
  7. 一招教你舍友学会尤克里里 | 今日最佳
  8. 消息队列-Message Queue
  9. MacBook运行C++,不用安装任何软件
  10. 关于使用,NI采集卡+labview信号采集,问题交流【第二贴】
  11. 如何编写项目发布文档
  12. 科研热点|官宣!2022年JCR分区和影响因子发布时间确定!
  13. 计算机黑屏闪光标,电脑开机黑屏只有光标在闪的解决方法
  14. java resourcebundle_Java ResourceBundle.getBundle如何加载属性文件?
  15. 测试方案和测试计划区别
  16. js设置北京时区_JavaScript 实现北京时间转其他时区时间,根据系统对对应时区转换...
  17. 在excel中使用宏和公式把汉字转换成拼音
  18. 不用注册表删除搜狗输入法残留文件夹
  19. Hyper-V配置ubuntu网络(无线有限均可)
  20. 【网络通信】Teardrop编程创造虚假IP包

热门文章

  1. java 判断是否为邮箱_Java判断邮箱是否存在 有返回值
  2. 学完javase和mysql_Java基础学完接下来应该学什么呢?
  3. 学习UI设计能做什么
  4. ZStack--通过Ansible实现全自动化
  5. shiro多realm验证之——shiro实现不同身份使用不同Realm进行验证(转)
  6. Linux下,各种解压缩命令集合
  7. 怎样在Red Hat Enterprise Linux 5.4版本上安装GCC?
  8. 解析腾讯行政区划API接口数据
  9. c语言饭卡管理系统链表文件,C语言《学生信息管理系统》链表+文件操作
  10. java连接数据库不使用框架_实体框架数据库连接不重新连接