Codeforces Round #402 (Div. 2) B
Description
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 3000 that 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 by10k. 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.
题意:删除第一个数字某些位数,可以使得被10K整除,求最少次数
解法:倒着遍历记录0的个数,以及不为0的个数,如果0的个数等于K,跳出遍历,输出不为0的个数,还有始终达不到K的情况,因为题目说一定有解,那么最后留下来的只有0,也就是输出数字的长度-1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string s;
ll num=;
ll ans=;
ll k;
cin>>s>>k;
for(int i=s.size()-; i>=; i--)
{
if(s[i]=='')
{
num++;
if(num>=k)
{
break;
}
} else
{
ans++;
}
}
if(num==k)
{
cout<<ans<<endl;
}
else
{
cout<<s.size()-<<endl;
}
return ;
}
Codeforces Round #402 (Div. 2) B的更多相关文章
- 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
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- 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) D. String Game
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- 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 ...
- 【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) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #402 (Div. 2) 阵亡记
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
随机推荐
- 软件版本号(BETA、RC、ALPHA、Release、GA等)
Alpha: Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用.是希腊字母的第一位,表示最初级的版本,alpha 就是α,beta 就是β , ...
- MFC 的 Picture Control 加载 BMP/PNG 图片的方法
1. 加载 BMP CStatic* pWnd = (CStatic*)GetDlgItem(IDC_PIC); // 得到 Picture Control 句柄 pWnd->ModifySty ...
- java面试题(摘录)
1.抽象,继承,封装,多态 2.基本数据类型的字节数 byte:1.int:4.char:2.long:8.float:4.double:8.boolean:1 和short:2 3.String , ...
- Messaging Patterns for Event-Driven Microservices
Messaging Patterns for Event-Driven Microservices https://content.pivotal.io/blog/messaging-patterns ...
- Latex 5: LaTeX资料下载
转: LaTeX资料下载 最全latex资料下载 LaTeX命令速查手册1
- java和jar命令
IDEA打可运行jar http://bglmmz.iteye.com/blog/2058785 -jar参数运行应用时classpath的设置方法 你是否在使用java -jar参数运行打包好的ja ...
- HTML&CSS——background: url() no-repeat 0 -64px;CSS中背景图片定位方法
CSS中背景图片的定位,困扰我很久了.今天总算搞懂了,一定要记下来. 在CSS中,背景图片的定位方法有3种: 1)关键字:background-position: top left; 2)像素:bac ...
- eclipse安装lombok和常用注解使用
1.下载lombok.jar lombok 的官方网址:http://projectlombok.org/ 2.运行lombok.jar: java -jar D:\eclipse-luna\l ...
- SPOJ:NO GCD (求集合&秒啊)
You are given N(1<=N<=100000) integers. Each integer is square free(meaning it has no divisor ...
- this关键字使用
原文地址:https://www.cnblogs.com/alsf/p/5515996.html 一,表示类中属性 1,没有使用this的情况 class Person{ // 定义Person类 p ...