Codeforces 835 B The number on the board
来源:互联网 发布:查看手机ip和端口 编辑:程序博客网 时间:2024/06/07 07:23
题目地址
题意:给你个字符串,把每个字符的和求出来,然后修改最少的字符数使它的和大于等于n
思路:记录每个字符的个数,并且求出当前和与n的差值,然后从最小的字符把它改成9,然后判断下是不是到了n就好了
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define N 50010#define M 200010#define K 1000010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1using namespace std;const LL mod = 1e9 + 7;const double eps = 1e-9;vector<int>num[10];int main() { cin.sync_with_stdio(false); string str; LL n, sum; while (cin >> n) { cin >> str; sum = 0; for (int i = 0; i < str.length(); i++) { sum += (str[i] - '0'); num[str[i] - '0'].push_back(i); } if (sum >= n) { cout << "0" << endl; } else { LL cnt = 0; sum = n - sum; for (int i = 0; i < 10; i++) { int len = num[i].size(); LL ans = len * (9 - i); if (ans >= sum) { cnt += sum / (9 - i); if (sum % (9 - i)) { cnt++; } break; } else { cnt += len; sum -= ans; } } cout << cnt << endl; } } 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
- Apache2.2配置虚拟机
- 正则表达式匹配不包含某些字符串的技巧
- EasyUI管理后台模板(附源码)
- 自行控制loadrunner的socket协议性能测试 (转) 一前言 二任务的提出 三实现方案讨论 四技术要点讲解 如何开始录制一个最简单的收发数据包脚本 写日志文件 一行一行读数据包文件 字
- JavaWeb动态导出Excel可弹出下载
- Codeforces 835 B The number on the board
- Android Studio 配置使用GreenDao3.0
- Cow Navigation
- android studio 中去除标题栏(全屏显示)
- Java并发编程实战(学习笔记 一 第二章 线程安全性)
- nested exception is java.lang.NoClassDefFoundError: org/springframework/data/geo/GeoResults
- Linux目录结构及文件基本操作
- 总结一下vxWorks中系统时钟是怎么修改延迟任务的时间片的
- linux安装nexus(支持jdk1.7)