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 < ...
随机推荐
- k8s的资源限制及资源请求
容器的资源需求及限制: 需求:requests ##定义容器运行时至少需要资源 限制:limits ##定义容器运行时最多能分配的资源 requests:pod.spec.con ...
- 基于axios的vue插件,让http请求更简单
ajax-plus 基于axios 的 Vue 插件 如何使用 npm 模块引入 首先通过 npm 安装 ```npm install --save ajax-plus or yarn add aja ...
- vue.js笔记1.0
事件: 事件冒泡行为: 1.@click="show($event)" show:function (ev) { ev.cancelBubble=true; } 2.@click. ...
- Gym - 100781G Goblin Garden Guards (扫描线)
题意: n 只哥布林,每只哥布林都有一个位置坐标. m 个炮台,每个炮台都有一个位置坐标和一个攻击半径. 如果一个哥布林在任何一个炮台的攻击范围内,都会被杀死. 求最后没有被杀死的哥布林的数量. 这题 ...
- CodeForce:732B-Cormen — The Best Friend Of a Man
传送门:http://codeforces.com/problemset/problem/732/B Cormen - The Best Friend Of a Man time limit per ...
- Django数据库的查看、删除,创建多张表并建立表之间关系
配置以下两处,可以方便我们直接右键运行tests.py一个文件,实现对数据库操作语句的调试: settings里面的设置: #可以将Django对数据库的操作语法,能输出对应的的sql语句 LOGGI ...
- uiautomator 一个简单脚本创建流程
http://www.codeceo.com/article/android-ui-auto-test.html
- Java学习ing
ConcurrentHashMap从JDK1.5开始随java.util.concurrent包一起引入JDK中,主要为了解决HashMap线程不安全和Hashtable效率不高的问题. Concur ...
- 九度oj 题目1380:lucky number
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...
- beautifusouptest
from bs4 import BeautifulSoupimport urllib.requesturl = "http://www.douban.com/tag/%E5%B0%8F%E8 ...