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.

Input

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.

Output

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).

Examples

input

30020 3

output

1

input

100 9

output

2

input

10203049 2

output

3

Note

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

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define  ll long long
 4 int main()
 5 {
 6     string s;
 7     ll num=0;
 8     ll ans=0;
 9     ll k;
10     cin>>s>>k;
11     for(int i=s.size()-1; i>=0; i--)
12     {
13         if(s[i]==‘0‘)
14         {
15             num++;
16             if(num>=k)
17             {
18                 break;
19             }
20         }
21
22         else
23         {
24             ans++;
25         }
26     }
27     if(num==k)
28     {
29         cout<<ans<<endl;
30     }
31     else
32     {
33         cout<<s.size()-1<<endl;
34     }
35     return 0;
36 }
时间: 2024-10-09 04:50:51

Codeforces Round #402 (Div. 2) B的相关文章

Codeforces Round #402 (Div. 2) C. Dishonest Sellers

题目链接:Codeforces Round #402 (Div. 2) C. Dishonest Sellers 题意: 有n个商品,每个商品这一周为ai的价格,下一周为bi的价格. 现在那个人要将这n个商品全部买掉,这一周最少要买k个商品, 为最小的花费是多少. 题解: xjb贪心一下. 按ai-bi排序,为负的要全部买掉,然后如果小于k件,就买前k件. 最后再买下一周的. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i&

Codeforces Round #402 (Div. 2) D. String Game

题目链接:Codeforces Round #402 (Div. 2) D. String Game 题意: 给你两个字符串a,b,然后给你n=strlen(a)个数字n1,n2,...,nn,表示依次删a[ni-1]个字符. 当a串删到有k(k任意)个子串组合起来(顺序不变)刚好等于b串时,就不能删了. 比如 abba->(ab a) 刚好包括 aba ,bba不包括aab. 问最多能删多少次. 题解: 最开始还以为是要用某种数据结构啥的,结果都想复杂了,直接二分答案就行. 然后线性判断删掉后

【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=100; bool vis[21]; void calc(int now) { int t=0; bool flag=0; for(int i=m;i>=1;--i) if(!vis[i]) { if((!flag) && a[i]==0) return; t=t*10+a[i]; fla

Codeforces Round #402 (Div. 2)

补的,不过都是自己做的. A.Pupils Redistribution [数学] 题意:交换A.B两数组中的元素,使得两组数组含1.2.3.4.5元素的个数相等. 做法:统计A组中1~5的个数,B组中减去.统计正数/2.负数/2绝对值,求两者最大值.数学问题,自己推一下. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include <bits/stdc++.h> #defi

Codeforces Round #402 (Div. 2) A

Description In Berland each high school student is characterized by academic performance - integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An a

Codeforces Round #402 (Div. 2) C

Description Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are

Codeforces Round #402 (Div. 2) D

Description Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the w

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i