AC日记——Weird Rounding Codeforces 779b
1 second
256 megabytes
standard input
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.
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.
思路:
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的更多相关文章
- AC日记——Cards Sorting codeforces 830B
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Card Game codeforces 808f
F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...
- AC日记——Success Rate codeforces 807c
Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——T-Shirt Hunt codeforces 807b
T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Magazine Ad codeforces 803d
803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...
- AC日记——Broken BST codeforces 797d
D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- AC日记——Vicious Keyboard codeforces 801a
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...
随机推荐
- 02Vs2013常用路径配置
1.设置头文件路径 项目 -> xxx属性页 -> 配置属性 -> C/C++ -> 常规 -> 附加包含目录. 2.包含 x.lib 库路径 项目 -> xxx属 ...
- 无法重启ssh
rm /dev/null mknod /dev/null c 1 3 chmod 666 /dev/null
- mysql 编程初步
mysql 编程 基本语法形式: 语句块模式 [begin_label] begin [statement_list] end [end_label]; label 标识符可以省略,但必须相同 流程控 ...
- python中字符串的一些用法
一.字符串的拼接: a=‘123’ b=‘abc’ d=‘hello world’ 1.print(a+b) 2.print(a,b) 3. c=‘ ’.join((a ...
- 剑指Offer(书):不用四则运算做加法
题目:写一个函数,求两个整数之和,不得使用四则运算位运算. package com.gjjun.jzoffer; /** * 写一个函数,求两个整数之和,不得使用四则运算 * * @author gj ...
- debian7安装icedove
stable --icedove --esr $ cat /etc/apt/sources.list | grep "deb http://security.debian.org/ whee ...
- meteor 检测运行环境,手机或者桌面
meteor add mystor:device-detection Meteor.Device.isPhone() https://atmospherejs.com/mystor/device-de ...
- Django Form one
前戏: FromData:三种方式获取FromData 1. 创建一个FromData 的对象,然后再用append 的方法追个添加键值对 var formdata = new FormData(); ...
- Andorid 生成NDK动态链接库 .so库
.so库第一次见到是在搜索Android保存静态秘钥等特殊id字段做法时看到的-通过NDK的方式将静态秘钥保存在so文件中, 关于原生开发工具包(NDK)详细见官网指南要更详细,这里我记录我度娘各种结 ...
- 聊聊、Nginx 初始化错误信息
这篇文章我们继续学习 main 方法,我们先来看看 ngx_debug_init() 这个方法. 从方法名我们也知道,debug初始化.我们先看看方法位置在哪.我们来断点在这个方法上面. Functi ...