A. BowWow and the Timetable

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

In the city of Saint Petersburg, a day lasts for 2100 minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4k for each integer k≥0. Team BowWow has arrived at the station at the time s and it is trying to count how many trains have they missed; in other words, the number of trains that have departed strictly before time s. For example if s=20, then they missed trains which have departed at 1, 4 and 16. As you are the only one who knows the time, help them!

Note that the number s will be given you in a binary representation without leading zeroes.

Input

The first line contains a single binary number s (0≤s<2100) without leading zeroes.

Output

Output a single number — the number of trains which have departed strictly before the time s.

Examples

inputCopy

100000000

outputCopy

4

inputCopy

101

outputCopy

2

inputCopy

10100

outputCopy

3

Note

In the first example 1000000002=25610, missed trains have departed at 1, 4, 16 and 64.

In the second example 1012=510, trains have departed at 1 and 4.

The third example is explained in the statements.

题意:

给你一个二进制的数x,问有多少个4^i 小于x

思路:

因为给的是二进制数,

我们知道一个二进制的数右移一位是除以2,那么右移两位就是除以4,

那么我们只需要看二进制数能右移2位几次即可,这个只需要二进制的长度即可判定。

又因为要求严格的小于x,那么如果是1000000,这样的数字,其实有效到的是 111111 ,即有效位数是减去1的。

那么直接有效长度/2就是答案

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout); string str;
cin>>str;
ll ans=0ll;
int flag=1;
for(int i=1;i<sz(str);++i)
{
if(str[i]!='0')
{
flag=0;
}
}
int len=sz(str);
if(flag)
{
len--;
}
ans=(len+1)/2;
cout<<ans<<endl; return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)的更多相关文章

  1. Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学

    Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ...

  2. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  3. Codeforces Round #581 (Div. 2)

    A:暴力. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm& ...

  4. 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)

    题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...

  5. Codeforces Round #581 (Div. 2) C. Anna, Svyatoslav and Maps (Floyd 算法,最短路)

    C. Anna, Svyatoslav and Maps time limit per test2 seconds memory limit per test256 megabytes inputst ...

  6. D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)

    D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...

  7. Codeforces Round #581 (Div. 2) B. Mislove Has Lost an Array (贪心)

    B. Mislove Has Lost an Array time limit per test1 second memory limit per test256 megabytes inputsta ...

  8. Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...

  9. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

随机推荐

  1. idea debug的drop frame,set watch和设置过滤条件

    idea debug中的drop frame就是回退到上一个方法调用的开始处,在IDEA里测试无法一行一行地回退或回到到上一个断点处,而是回到上一个方法. 在调用栈方法上选择要回退的方法,右键选择Dr ...

  2. com.jniwrapper.util.ProcessorInfo

    MyEclipse 9.x Crack报错 com.jniwrapper.util.ProcessorInfo usercode or systemid is empty! 卸载JDK9,改成JDK8

  3. SQL中group by使用

    多条重复记录,有一个字段可以进行区分,从重复的记录中取出其中一条,可利用group by字段 举例如下: 查询所有 查询地区中的最高分

  4. POJO是什么,javabean是什么,以及POJO与javabean的区别

    POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称.使用POJO名称是为了避免和EJB混淆起来, 而 ...

  5. document.documentElement 和 document.body

    MDN : The Document.documentElement read-only property returns the Element that is the root element o ...

  6. JavaScript(1)——编程真善美

    编程真善美 命名风格: 驼峰命名法 小驼峰法 变量一般用小驼峰法标识.驼峰法的意思是:除第一个单词之外,其他单词首字母大写:camelCase 大驼峰法(即帕斯卡命名法) 相比小驼峰法,大驼峰法把第一 ...

  7. EMA指数平滑移动平均

    英文参考:http://www.incrediblecharts.com/indicators/exponential_moving_average.php Exponential moving av ...

  8. 关于js中断ajax请求

    停止javascript的ajax请求,一种是设置超时时间让ajax自动断开,另一种为手动去停止ajax请求,其核心是调用XMLHttpRequest对象上的abort方法,这里,我们以jquery举 ...

  9. Nginx实现负载均衡的方式有哪几种呢?

    什么是负载均衡 当一台服务器的单位时间内的访问量越大时,服务器压力就越大,大到超过自身承受能力时,服务器就会崩溃.为了避免服务器崩溃,让用户有更好的体验,我们通过负载均衡的方式来分担服务器压力. 我们 ...

  10. python 实现 灰色预测 GM(1,1)模型 灰色系统 预测 灰色预测公式推导

    来源公式推导连接 https://blog.csdn.net/qq_36387683/article/details/88554434 关键词:灰色预测 python 实现 灰色预测 GM(1,1)模 ...