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看了看,不会,弃 ...
随机推荐
- 有奖试读&征文——我们在互联网上奋斗的故事 获奖名单发布
互联网是一个年轻的行业,同一时候也是一个推陈出新.不断进化的行业. 中国互联网行业在近期的十五年里.以如何的方式在"进化".我相信非常多奋斗在互联网战线上的你们最深有感触.读一读& ...
- js中的连等==和全等===
===是没有强制类型转换的,和其他大部分语言的==是一样的.而js中==是有类型转换的. 比如说"true"==true就是错的,Boolean("false" ...
- td 中设置超出宽度显示省略号失效
td测试内容超出显示省略号时,结果没有显示省略号,而是一直往后显示,且超出了td大小,强行挤大了table. 原因是因为td默认不换行. 解决方法: 1.强制td换行. IE加上word-break: ...
- Redis实现中间件(订阅)
什么是消息中间件 发布订阅 点对点 消息中间件本身是异步的通讯 案例:使用redis实现发布订阅功能 Redis发布订阅 Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub) ...
- poj 1094 Sorting It All Out 解题报告
题目链接:http://poj.org/problem?id=1094 题目意思:给出 n 个待排序的字母 和 m 种关系,问需要读到第 几 行可以确定这些字母的排列顺序或者有矛盾的地方,又或者虽然具 ...
- [Selenium] 如何使 InternetExplorerDriver 每次启动的端口不会随机变化
InternetExplorerDriver 在不指定任何参数的情况下,启动监听端口会随机变化.如果需要保证其端口固定不变,可通过InternetExplorerDriverService 达到目的. ...
- BZOJ_2186_[Sdoi2008]沙拉公主的困惑_欧拉函数
BZOJ_2186_[Sdoi2008]沙拉公主的困惑_欧拉函数 Description 大富翁国因为通货膨胀,以及假钞泛滥,政府决定推出一项新的政策:现有钞票编号范围为1到N的阶乘,但是,政府只发行 ...
- IOCP编程小结(上)
前段时间接手了一个网络游戏前端连接服务器的开发工作,由于服务器需要在windows平台上部署,并且需要处理大量的客户端连接,因此采用IOCP来做为服务器端的编程模型就成了不二选择.虽然我对服务器开发并 ...
- saltstack自动化运维快速入门
saltstack自动化运维快速入门 关于saltstack 这个软件是干啥的 我这里就不介绍了 只是简单的说下是干啥的 网上的说法是 它是func的强化版本+ puppet的精简版 关于puppet ...
- WaveNet: 原始音频生成模型
官方博客 WaveNet: A Generative Model for Raw Audio paper地址:paper Abstract WaveNet是probabilistic and auto ...