Codeforces #835B: The Number on the Board 题解
来源:互联网 发布:java开发外包 编辑:程序博客网 时间:2024/06/06 19:37
将所有数字放进数组排个序
贪心的选择先修改小的数字,将其修改成9,这样可以最大化k步之后的数字和
然后模拟一下就可以了
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cmath>#include <algorithm>#include <cstdlib>#include <utility>#include <map>#include <stack>#include <set>#include <vector>#include <queue>#include <deque>#define x first#define y second#define mp make_pair#define pb push_back#define LL long long#define Pair pair<int,int>#define LOWBIT(x) x & (-x)using namespace std;const int MOD=1e9+7;const int INF=0x7ffffff;const int magic=348;char s[200048];int k;int sum=0,l;int a[200048];int main (){int i;scanf("%d",&k);scanf("%s",s+1);l=strlen(s+1);for (i=1;i<=l;i++){sum+=s[i]-'0';a[i]=s[i]-'0';}sort(a+1,a+l+1);if (sum>=k){printf("0\n");return 0;}for (i=1;i<=l;i++){sum+=9-a[i];if (sum>=k){printf("%d\n",i);return 0;}}return 0;}
阅读全文
0 0
- Codeforces #835B: The Number on the Board 题解
- codeforces B. 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
- python基础name&direction
- echarts重写图例点击事件
- 虚拟币开发专题(关于山寨币的区块链你了解多少)
- bootstraptable的加载刷新数据
- JavaDay04循环题目的简单思路(菱形,日历)随机数,函数
- Codeforces #835B: The Number on the Board 题解
- Java代码优化
- Netty连接池ChannelPool,FixedChannelPool应用
- 一些常用的资源框架
- 工作流学习——Activiti整体认识二步曲
- iOS自定义打印开关
- Java
- linux下web集群环境部署
- java.io.IOException: Could not locate executablenull\bin\winutils.exe in the Hadoop binaries