Codeforce 835B - The number on the board (贪心)
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
The first line contains integer k (1 ≤ k ≤ 109).
The second line contains integer n (1 ≤ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Print the minimum number of digits in which the initial number and n can differ.
3
11
1
3
99
0
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.
题解:之前几次都会错题意 哇了好几次 第二天看分类说是贪心 那就贪心吧 每位数字最大到9 如果总和比k小的话 就把差最大的改为9
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
const int N=;
const int mod=1e9+;
char a[N];
int main()
{
int k;
scanf("%d",&k);
scanf("%s",&a);
int len=strlen(a);
int s=;
for(int i=;i<len;i++){
s+=a[i]-'';
}
sort(a,a+len);
if(s>=k) cout<<<<endl;
else {
int t=;
for(int i=;i<len;i++){
s+=-(a[i]-'');
t++;
if(s>=k){
break;
}
}
cout<<t<<endl;
}
return ;
}
Codeforce 835B - The number on the board (贪心)的更多相关文章
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心
Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...
- CodeForce 359C Prime Number
Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1, ...
- cf201.div1 Number Transformation II 【贪心】
1 题目描述: 被给一系列的正整数x1,x2,x3...xn和两个非负整数a和b,通过下面两步操作将a转化为b: 1.对当前的a减1. 2.对当前a减去a % xi (i=1,2...n). 计算a转 ...
- codeforce 804B Minimum number of steps
cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...
- (Codeforce)The number of positions
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say ...
- 【Codeforces Round #427 (Div. 2) B】The number on the board
[Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...
- Largest Beautiful Number CodeForces - 946E (贪心)
题意:给定一个长度为偶数的数,输出小于它的最大的美丽数.如果一个数长度为偶数,且没有前导零,并存在一种排列是回文数的数为美丽数.给定的t个数长度总和不超过200000. 分析: 1.存在一种排列为回文 ...
- Display number of replies in disscussion board
how to display number of replies in disscussion board I have a require about display the replies' nu ...
随机推荐
- nginx做正向代理
#代理服务器设置 server { resolver 8.8.8.8; resolver 114.114.114.114; listen ; access_log /home/lin/proxy.ac ...
- C# install-package:"xx"已拥有为“xxx”定义的依赖项
可能 nuget自身的版本落后于适配程序包的版本 Visual Studio 2013 更新 NuGet 包管理器 Ø 前言 使用 Visual Studio 中的 NuGet 包管理器下载程序时, ...
- NYOJ 会场安排问题
#include<iostream> #include<stdio.h> #include<string.h> #include<queue> #inc ...
- openshift 容器云从入门到崩溃之二《准备环境》
openshift 从3.9开始就开始支持系统组件在容器里运行了,之前版本都是直接运行在操作系统上,名字也改了叫OKD 目前最新的稳定版本是3.11,所以就安装3.11版本 准备环境: 主机名 系统 ...
- python导入csv/txt文件
1. 导入csv文件 ### python导入csv文件的三种方法 ```python #原始的方式 lines = [line.split(',') for line in open('iris.c ...
- iOS 开发笔记-Objective-C之KVC、KVO
概述 键值编码(KVC).键值监听(KVO)特性 键值监听KVO Key Value Observing(简称KVO)其实是一种观察者模式,利用它可以很容易实现视图组件和数据模型的分离,当数据模型的属 ...
- JAVA编程思想学习笔记2-chap4-6-斗之气2段
1.foreach:只能用于数组与容器 2.this指针:内部有个指针指向自己 3.super指针:内部有个指针指向父类部分 4.方法存放于代码区:方法调用时,a.fun()可能会被转换为fun(a) ...
- Windows服务器时间不同步问题
一台域内的服务器时间不停地被修改,我先向用户收集了一些信息 只有这一台出现此问题,其他服务器均为正常(补充一下,问题快解决完的时候用户告诉我一个重要的消息,就是时间被修改了一段时间后自动会被修改回去) ...
- 解决Windows内存问题的两个小工具RamMap和VMMap
解决Windows内存问题需要对操作系统的深入理解,同时对于如何运用Windows调试器或性能监控器要有工作认知.如果你正试着得到细节,诸如内核堆栈大小或硬盘内存消耗,你会需要调试器命令和内核数据架构 ...
- AM自动化测试平台
AM自动化测试平台介绍: 最初目标:是为了做接口自动化测试,该平台,集成了,用例管理,测试执行,测试套件(主要为了应对,对场景业务流程有需要的),测试报告展示. 后期目标:适当增加,其它测试工具进行集 ...