B. Weird Rounding
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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, ifk = 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.

思路:

  dfs~~~~;

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; int n,k,len,ans=0x7fffffff,p; char ch[]; bool if_[]; bool check()
{
int bzero=;
bool zero=true;
long long int pos=;
for(int i=;i<=len;i++)
{
if(if_[i]) continue;
if(zero)
{
if(ch[i]=='') bzero++;
else
{
zero=false;
pos=pos*+ch[i]-'';
}
}
else pos=pos*+ch[i]-'';
}
if(bzero==&&pos==) return true;
if(bzero>) return false;
if(pos%p==) return true;
return false;
} void dfs(int step,int ci)
{
if(step>=ans) return ;
if(check())
{
ans=step;
return ;
}
for(int i=ci+;i<=len;i++)
{
if(!if_[i])
{
if_[i]=true;
dfs(step+,i);
if_[i]=false;
}
}
} int main()
{
cin>>ch+;
cin>>k;
p=;
for(int i=;i<=k;i++) p=p*;
len=strlen(ch+);
dfs(,);
cout<<ans;
return ;
}

AC日记——Weird Rounding Codeforces 779b的更多相关文章

  1. AC日记——Cards Sorting codeforces 830B

    Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  2. AC日记——Card Game codeforces 808f

    F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...

  3. AC日记——Success Rate codeforces 807c

    Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  4. AC日记——T-Shirt Hunt codeforces 807b

    T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  5. AC日记——Magazine Ad codeforces 803d

    803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...

  6. AC日记——Broken BST codeforces 797d

    D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...

  7. AC日记——Array Queries codeforces 797e

    797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...

  8. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

  9. AC日记——Vicious Keyboard codeforces 801a

    801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. knn算法之预测数字

    训练算法并对算法的准确值准确率进行估计 #导入相应模块 import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%mat ...

  2. NFS搭建

    一.环境 nfsserver01:192.168.127.100  centos7.3 nfsclient01:192.168.127.101  centos7.3 二.NFS原理 三.安装测试 1. ...

  3. Library setup

  4. java中常用的集合的一些区别 (2013-10-07-163写的日志迁移

    java中的以下几大集合: List结构的集合类: ArrayListl类,LinkedList类,Vector类,stack类 Map结构的集合类: HashMap类,Hashtable类(此是以k ...

  5. 解决 viewer.js 动态更新图片导致无法预览的问题

    1.viewer.js 使用 Demo http://fengyuanchen.github.io/viewerjs/ 2.viewer.js 下载地址 https://github.com/feng ...

  6. manjaro kde netease-cloud-music 网易云音乐

  7. poj 3050 地图5位数问题 dfs算法

    题意:一个5*5地图上面,从任意位置上下左右跳五次,组成一个数.问:不重复的数有多少个? 思路:dfs 从任意位置跳5次,说明每个位置都需要遍历. 组成一个数:number*10+map[dx][dy ...

  8. bash数组操作-定义/初始化/赋值…

    数组:     连续的多个独立内存空间,每个内存空间相当于一个变量     数组元素:数组名+索引         索引:从0开始编号             声明数组:         declar ...

  9. luogu1441 砝码称重

    搜索+背包就是了 #include <iostream> #include <cstring> #include <cstdio> using namespace ...

  10. 带有命名空间的xml解析,C#

    前一段时间做花旗的接口,返回的xml格式是带有命名空间的,可是难倒了我,找了好久才找到解决办法,给大家分享下,少走弯路. 1,直接进入正题,先看一段带有命名空间的xml,这段xml大概的意思是,前面是 ...