CF779B(round 402 div.2 B) Weird Rounding
题意:
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 3000that 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 by 10k. 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.
思路:
模拟,贪心。
实现:
#include <cstdio>
#include <string>
#include <iostream>
using namespace std; int main()
{
string s;
int t;
cin >> s >> t;
int n = s.length();
int cnt = ;
for (int i = ; i < n; i++)
{
if (s[i] == '')
cnt++;
}
if (cnt >= t)
{
int f = ;
int num0 = ;
for (int i = n - ; i >= ; i--)
{
if (s[i] == '')
{
num0++;
if (num0 == t)
break;
}
else
{
f++;
}
}
cout << f << endl;
}
else
cout << n - << endl;
return ;
}
CF779B(round 402 div.2 B) Weird Rounding的更多相关文章
- 【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) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- 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,E
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 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 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
- Codeforces Round #407 (Div. 2) D. Weird journey(欧拉路)
D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #402 (Div. 2) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #407 (Div. 1) B. Weird journey —— dfs + 图
题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds m ...
随机推荐
- eureka-注册中心使用密码验证
spring cloud 1.1 版本之后可以使用 配置文件: bootstrap.yml server.port: 9000 spring.application.name: registry eu ...
- @SpringBootApplication 注解
@SpringBootApplication 启动类注解(一般在root下):该注解被@Configuration.@EnableAutoConfiguration.@ComponentScan 这三 ...
- maven实战(1)-- maven仓库
maven仓库配置 转自:http://blog.csdn.net/dongnan591172113/article/details/7685164 1.两类仓库 1.1本地仓库(local repo ...
- web 基本概念辨异 —— URI 与 URL
两者的相同点: 都是唯一的,对资源(R:Resource)起到唯一的标识作用: 两者的不同点: URL 是 URI 的子集(URI 是父类,URL 是子类),是一种特定的实现形式: URI 可以是身份 ...
- JSON --- 一种轻量级的数据交换格式
目录 1. 语法 2. 解析与序列化 JSON.stringify( jsData[, filter, indent] ) JSON.parse( jsonData[, reduction]) JSO ...
- bzoj3653
主席树+dfs序 b在a上方时可以O(1)算出来,子树中就用主席树查询区间和,权值线段树的下标是深度,值是子树size-1,每次查询就行了...线段树合并挂了 #include<bits/std ...
- 修改CentOS系统的默认启动级别
======修改CentOS系统的默认启动级别====== 现在的Linux系统安装完后就运行在第5个级别,即系统启动后直接进入图形界面,而不用在字符模式下登录后用startx或者xinit来起动图形 ...
- Codeforces630C【水题】
题意: 有一种数只会有7或者8构成,给一个n,问你前n位上有多少个这样的数. 思路: 对于一个 i 位,有2^i个数,然后前n项和就是2^(n+1)-2; 复习一下等比数列求和,等差数列求和吧; ①: ...
- 洛谷P3577 [POI2014]TUR-Tourism
给定一个n个点,m条边的无向图,其中你在第i个点建立旅游站点的费用为Ci.在这张图中,任意两点间不存在节点数超过10的简单路径.请找到一种费用最小的建立旅游站点的方案,使得每个点要么建立了旅游站点,要 ...
- PJzhang:工作之余一起来看剧
猫宁!!! 最近几个月陆续看了4部电视剧,不错,分别来自4个国家或地区,英国.日本.中国香港.俄罗斯,是的,没有美剧,平时真的很少看美剧. 1-IT狂人,英剧,一共4季,每季6集,每集25分钟左右. ...