Codeforces Round #427 (Div. 2) - B
题目链接: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的更多相关文章
- 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) 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 ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- 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)——ABCD
http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- 【Codeforces Round #427 (Div. 2) A】Key races
[Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...
随机推荐
- 安装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 ...
- Java之Integer类
Integer类简介: Integer类是基本数据类型int的包装器类,是抽象类Number的子类,位于java.lang包中. Integer类在对象中包装了一个基本类型int的值,也就是每个Int ...
- zabbix 监控hp 打印机
https://share.zabbix.com/search?searchword=hp+printer&search_cat=1
- 自动化运维--ansible(2)
问题一:如何在多台服务器中配置Web项目上线的所有环境 解答: 1.使用ansible配置nginx服务 在安装前了解rpm与yum的区别 rpm是压缩包安装依赖包需要自己手动安装,yum安装解决依 ...
- OpenStack 实现技术分解 (6) 通用库 — oslo_log
目录 目录 前文列表 扩展阅读 日志级别 oslolog 初始化设置 DEMO oslolog 的相关配置项 oslolog 的日志级别 oslolog 的使用技巧 推荐使用 LOGdebug 的地方 ...
- What is the difference between a URI, a URL and a URN?
资料: URI: URL: URN:
- Jmeter之保存响应到文件
在jmeter中使用保存响应到文件 ------适用于非GUI模式执行脚本时,无法查看报错的信息. 1.添加组件: 2.各个配置项说明: (1.名称:即组件在整个测试计划中的名称显示,建议设置为用意义 ...
- dcef3 指出一个坑
dcef3 指出一个坑 http://ju.outofmemory.cn/entry/80119 BccSafe's Blog 2014-06-11 2388 阅读 dcef3提供了TChromi ...
- ABAP基本数据类型
ABAP 程序中共包含8种基本数据类型: 数据类型名称 描述 属 性 C Character Text(字符类型) 默认长度=1,默认值=blank,最大长度无限制 N Numeric Text(数 ...
- node-webkit-updater——NW.js自动更新
NW.js自动更新三种方案: 1)node-webkit-updater(推荐) 2)nwjs-autoupdater 3)nw-autoupdater NW.js自动更新三种方案:[http://d ...