CodeForces 835B The number on the board
来源:互联网 发布:知乎营销案例 编辑:程序博客网 时间:2024/06/06 18:29
题目链接:http://codeforces.com/contest/835/problem/B
题意:黑板上有一个数,你只知道这个数的每一位的和不小于k,现在有一个人不小心改动了这个数,把这个数变成n了,现在问你这个人从最初的数最少改变了几位数
解析:首先先把n的每一位数求和,如果大于等于k那么就是没有改变,如果小于他,那肯定是从位数最小的数开始改变,然后扫一遍即可
#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+10;char a[maxn];int main(void){ int k,sum = 0; scanf("%d %s",&k,a); int len = strlen(a); sort(a,a+len); for(int i=0;i<len;i++) sum += a[i]-'0'; if(sum>=k) puts("0"); else { int tmp = k-sum; int cnt = 0,tt = 0; for(int i=0;i<len;i++) { tt += a[i]-'0'; cnt++; if(cnt*9-tt>=tmp) break; } printf("%d\n",cnt); } return 0;}
阅读全文
0 0
- codeforces B. The number on the board
- Codeforces 835B-The number on the board
- Codeforces #835B: The Number on the Board 题解
- Codeforces 835 B The number on the board
- Codeforces 835 B The number on the board
- CodeForces 835B The number on the board
- codeforces 835b The number on the board
- CodeForces 835 B.The number on the board(贪心)
- codeforces 835B The number on the board
- Codeforces 835B The number on the board (贪心)
- codeforces 835b 之 The number on the board
- codeforces 835B The number on the board
- (贪心)Codeforces Round #427 B. The number on the board
- codeforces 835B The number on the board (优先队列,贪心)
- Codeforces-The number on the board
- B. The number on the board
- Codeforces Round #427 (Div. 2) B. The number on the board
- Codeforces Round #427 (Div. 2)-B. The number on the board
- CodeForces
- IntelliJ IDEA注册激活
- 给定一个字符串类型的数组,数组元素值为数字组成的字符串对象, 将数组元素的进行拼接,拼接之后的数字值是最大的
- POJ 3278Catch That Cow (bfs)
- #Oracle-01
- CodeForces 835B The number on the board
- [转]STL 之set不允许元素重复,且从小到大排列
- 2017多校联合训练第3场第5题
- 利用tensorflow一步一步实现基于MNIST 数据集进行手写数字识别的神经网络,逻辑回归
- linkedList特有的方法
- 最大流dinic算法的优化模板 当前弧优化,多路增广
- 超好用的网络抓包框架(Windivert)之二(语言)
- Tensorflow学习笔记(3)-mnist(softmax regression)
- 浅谈Tomcat源码中Bootstrap类的四个方法