【Codeforces】835B The number on the board (贪心)
把所有字符串上的数字加起来,看是否超过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 (贪心)相关推荐
- 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 ...
- CodeForces 991E Bus Number DFS+ 组合数
CodeForces 991E Bus Number DFS+ 组合数 题目大意:给定一个数字,数字里出现的每一个数,都至少要用一个,问能组成多少个新数,不加前导零. input: 2028 outp ...
- Codeforces Round #774 (Div. 2) Power Board(数学)
Codeforces Round #774 (Div. 2) Power Board(数学) 链接 题意:给一个n*m的矩阵,每个元素的值是 i j i^j ij,问有多少个不一样的元素 思路:不过这 ...
- Codeforces Beta Round #11 A. Increasing Sequence 贪心
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- 【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 ...
- 【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 ...
- 【CodeForces - 589F】Gourmet and Banquet (贪心,思维,二分)
题干: A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet ...
最新文章
- Clojure程序设计
- accessid管理_Access班级管理的使用方法
- OpenCV学习:Mat结构中的数据共享机制
- opencv 显示图片(直接)
- 哲学家就餐问题php代码,Python实现哲学家就餐问题实例代码
- ASP.NET Core中的分布式缓存
- 一招教你舍友学会尤克里里 | 今日最佳
- 消息队列-Message Queue
- MacBook运行C++,不用安装任何软件
- 关于使用,NI采集卡+labview信号采集,问题交流【第二贴】
- 如何编写项目发布文档
- 科研热点|官宣!2022年JCR分区和影响因子发布时间确定!
- 计算机黑屏闪光标,电脑开机黑屏只有光标在闪的解决方法
- java resourcebundle_Java ResourceBundle.getBundle如何加载属性文件?
- 测试方案和测试计划区别
- js设置北京时区_JavaScript 实现北京时间转其他时区时间,根据系统对对应时区转换...
- 在excel中使用宏和公式把汉字转换成拼音
- 不用注册表删除搜狗输入法残留文件夹
- Hyper-V配置ubuntu网络(无线有限均可)
- 【网络通信】Teardrop编程创造虚假IP包
热门文章
- java 判断是否为邮箱_Java判断邮箱是否存在 有返回值
- 学完javase和mysql_Java基础学完接下来应该学什么呢?
- 学习UI设计能做什么
- ZStack--通过Ansible实现全自动化
- shiro多realm验证之——shiro实现不同身份使用不同Realm进行验证(转)
- Linux下,各种解压缩命令集合
- 怎样在Red Hat Enterprise Linux 5.4版本上安装GCC?
- 解析腾讯行政区划API接口数据
- c语言饭卡管理系统链表文件,C语言《学生信息管理系统》链表+文件操作
- java连接数据库不使用框架_实体框架数据库连接不重新连接