CF779B(round 402 div.2 B) Weird Rounding
题意:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000that is divisible by 103 = 1000.
Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).
It is guaranteed that the answer exists.
The only line of the input contains two integer numbers n and k (0 ≤ n ≤ 2 000 000 000, 1 ≤ k ≤ 9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.
Print w — the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).
30020 3
1
100 9
2
10203049 2
3
In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number.
思路:
模拟,贪心。
实现:
#include <cstdio>
#include <string>
#include <iostream>
using namespace std; int main()
{
string s;
int t;
cin >> s >> t;
int n = s.length();
int cnt = ;
for (int i = ; i < n; i++)
{
if (s[i] == '')
cnt++;
}
if (cnt >= t)
{
int f = ;
int num0 = ;
for (int i = n - ; i >= ; i--)
{
if (s[i] == '')
{
num0++;
if (num0 == t)
break;
}
else
{
f++;
}
}
cout << f << endl;
}
else
cout << n - << endl;
return ;
}
CF779B(round 402 div.2 B) Weird Rounding的更多相关文章
- 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding
暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...
- Codeforces Round #402 (Div. 2) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- Codeforces Round #402 (Div. 2)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- Codeforces Round #402 (Div. 2) A,B,C,D,E
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #402 (Div. 2) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
- Codeforces Round #407 (Div. 2) D. Weird journey(欧拉路)
D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #402 (Div. 2) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #407 (Div. 1) B. Weird journey —— dfs + 图
题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds m ...
随机推荐
- Silverlight中使用MVVM(2)
Silverlight中使用MVVM(1)--基础 Silverlight中使用MVVM(2)—提高 Silverlight中使用MVVM(3)—进阶 Silverlight中使用MVVM(4)—演练 ...
- oracle:os认证用户登录测试
90%的情况下,我们使用的都是数据库认证用户登录oracle,但还存在使用OS认证用户登录oracle的情况: 下面就实验一下OS用户要登录oracle相关操作: 测试环境:oracle10. ...
- codeforces 665E E. Beautiful Subarrays(trie树)
题目链接: E. Beautiful Subarrays time limit per test 3 seconds memory limit per test 512 megabytes input ...
- CodeForces985F:Isomorphic Strings (字符串&hash)
题意:取出字符串Str里的两个串S,T,问对应位置的的字符在否有一一映射关系. hash:对于每个字符s=‘a’-‘z’,我们任意找一个i,满足Si==s,(代码里用lower_bound在区间找到最 ...
- [POI 2014] Couriers
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3524 [算法] 首先离线 , 将询问按右端点排序 如果我们知道[l , r]这个区间 ...
- 【CAIOJ1177】 子串是否出现
[题目链接] 点击打开链接 [算法] KMP [代码] #include<bits/stdc++.h> using namespace std; #define MAXA 1000010 ...
- linux--vsftpd的安装和配置(转)
Linux下如何进行FTP设置(转) [TOC] Redhat/CentOS安装vsftp软件 1. 安装vsftp $ yum install vsftpd -y 2. 添加ftp帐号和目录 先检查 ...
- 移动web开发------公用css----自己总结
@charset "utf-8"; html, body { background: #fff; color: #505050; font-size: 10px; -moz-use ...
- Cmake生成Makefile
cmake 相比automake 最大的区别是: 步骤没有automake那么多 main.cpp #include<iostream> #include"student.h&q ...
- e_pro list 1
uncle n. 叔叔; 伯父; 舅父; 姑父,姨父; farm n. 农家; 农田; 农场,农庄; 畜牧场; corner n. 拐角; 角落,角; 困境; [商] 囤积; vi. 驾车转 ...