Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)
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 (思维)的更多相关文章
- 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] ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #581 (Div. 2)
A:暴力. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm& ...
- 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)
题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...
- 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 ...
随机推荐
- HBase 批量删除表 disable_all drop_all
这两命令可以匹配正则表达式,对表进行批量操作,也可以对确定名字的单表操作,在表名不存在时,也不会返回exception,只会有提示信息.\ny是为了实现自动确认,因为这两命令需要用户交互确认. 例子, ...
- PJzhang:今天才搞清身份证、银行卡……的编码规则
猫宁!!! 之前思考过常见证件的编码规则,抽空查了一下,发现挺有意思. 一般查询证件或者手机号归属地都是直接百度小工具,但是背后的查询机制如何,可能大多人不甚了解. 介绍几种生活中最 ...
- HCL试验六
交换机R1: syssysname R1interface loopback 0ip add 192.168.10.1 24quinterface g0/0ip address 10.1.1.1 30 ...
- python基础之元祖tuple
元祖是只读列表,不可哈希,可循环查询,可切片*儿子不能改,孙子可更改--元祖里面单个元素不能更改---元祖内列表可更改增:tu1+tu2查:tu1[index] tu1[start_index:end ...
- Java 使用第三方推送 -- 极光推送
官网链接 : https://www.jiguang.cn/ 注册完成登录后,点击创建应用 这里不细说 Java后端的整合如下: 添加maven依赖的包 <dependency> < ...
- Python 条件判断 和循环
使用条件判断 if else # 条件派单 if else print('条件派单 if else') # s = input('请输入生日年号:') # birth = int(s) birth = ...
- liunx忘记用户密码
1.vim /etc/my.cnf [mysqld] skip-grant-tables ##追加此行,跳过权限表, 2.重启mysql systemctl restart mysqld 3.mysq ...
- EM 算法(二)-KMeans
KMeans 算法太过简单,不再赘述 本文尝试用 EM 算法解释 KMeans,而事实上 KMeans 算是 EM 的一个特例 EM 算法是包含隐变量的参数估计模型,那对应到 KMeans 上,隐变量 ...
- redis集群搭建和哨兵模式以及AOF和RDB持久化
Redis主从+哨兵模式 1.环境准备 (1)三台独立的linux主机 (2)IP分别为:10.150.200.182 (从) 10.150.200.184(从) 10.150.200.195(主) ...
- SG函数和SG定理(Sprague_Grundy)
一.必胜点和必败点的概念 P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败. N点:必胜点,处于此情况下,双方操作均正确的情况下必胜. 必胜点和必败点的性质: ...