C. The Number Of Good Substrings

Problem Description:

You are given a binary string s (recall that a string is binary if each character is either 0 or 1).
Let f(t) be the decimal representation of integer t written in binary form (possibly with leading zeroes). For example f(011)=3,f(00101)=5,f(00001)=1,f(10)=2,f(000)=0 and f(000100)=4.
The substring sl,sl+1,…,sr is good if r−l+1=f(sl…sr).
For example string s=1011 has 5 good substrings: s1…s1=1, s3…s3=1, s4…s4=1, s1…s2=10 and s2…s4=011.
Your task is to calculate the number of good substrings of string s.
You have to answer t independent queries.
Input
The first line contains one integer t (1≤t≤1000) — the number of queries.
The only line of each query contains string s (1≤|s|≤2⋅105), consisting of only digits 0 and 1.
It is guaranteed that ∑i=1t|si|≤2⋅105.
Output
For each query print one integer — the number of good substrings of string s.

Input


Output


题意:求子串的个数。子串需要满足:长度与二进制数相同。

思路:先求每个1前面的0的个数 ,分别从1当前位置开始遍历字符串.计算f()函数值是否满足条件(长度==f()函数值).

AC代码:

#include<bits/stdc++.h>

using namespace std;
#define int long long
signed main(){
int _;
cin>>_;
while(_--){
string s;
cin>>s;
int ans=;
int zero=;
int len=s.size();
int sum=;// 计算f函数
for(int i=;i<len;i++){
if(s[i]==''){// 1的前面0 的个数
zero++;
}else{
sum=;
int cnt=;
for(int j=i;j<len;j++){
sum=sum*+s[j]-'';// f()函数值
cnt++;// 长度
if(sum>=len+){// f()>=字符串长度
break;
}
if(cnt+zero>=sum){ // 满足条件
ans++;
}
}
zero=;
}
}
printf("%lld\n",ans);
}
return ;
}

Educational Codeforces Round 72 (Rated for Div. 2) C题的更多相关文章

  1. Educational Codeforces Round 72 (Rated for Div. 2) B题

    Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...

  2. Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description: You play your favourite game yet another time. You chose the character you didn ...

  3. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  4. 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D

    https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...

  5. Educational Codeforces Round 72 (Rated for Div. 2)

    https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...

  6. Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...

  7. Educational Codeforces Round 72 (Rated for Div. 2) Solution

    传送门 A. Creating a Character 设读入的数据分别为 $a,b,c$ 对于一种合法的分配,设分了 $x$ 给 $a$ 那么有 $a+x>b+(c-x)$,整理得到 $x&g ...

  8. Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2)C(暴力)

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

随机推荐

  1. 位带操作—GPIO输出和输入

    GPIOC->ODR |=(0<<2);  // 总线操作,即操作整个寄存器. 在51单片机中 P0=0xFE;   //总线操作. sbit LED1=P0^0;  //位操作,即 ...

  2. GPIO 输出—使用固件库点亮 LED

    编程要点 1. 使能 GPIO 端口时钟:  2. 初始化 GPIO 目标引脚为推挽输出模式:  3. 编写简单测试程序,控制 GPIO 引脚输出高.低电平. LED的电路图 过程: 1.拷贝一个库函 ...

  3. 使用Python比较MySQL数据库中两个数据库的表结构--转载

    https://blog.csdn.net/tenaguan4461/article/details/82286781 https://www.jianshu.com/p/b3dac5a3479a

  4. Spring @Transactional注解在什么情况下会失效,为什么?

    出处:  https://www.cnblogs.com/hunrry/p/9183209.html   https://www.cnblogs.com/protected/p/6652188.htm ...

  5. spring cloud 停止服务

    shutdown的默认url为host:port/shutdown,当需要停止服务时,向服务器post该请求即可,如:curl -X POST host:port/shutdown将得到形如{&quo ...

  6. 前端 aes 加密

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. node 标准输入流和输出流

    使用node 在 CMD 控制台获取输入的指令: 方式一: process.stdin.resume(); process.stdin.setEncoding('utf-8'); process.st ...

  8. POJ2945(Find the Clones)--字典树,map

    题意:给你n个规定长度的单词,问你其中出现了1次的单词,出现两次的单词...出现n次单词分别有多少个. 当然这题map也能过,但是这里介绍字典树的做法. 首相对于n个单词存入树中,当然建树过程中遇到一 ...

  9. 基于【 centos7】二 || 系统时间与网络时间同步

    # date // 查看系统时间 #hwclock // 查看硬件时间 # yum -y install ntp ntpdate 安装ntpdate工具 # ntpdate cn.pool.ntp.o ...

  10. leetcode-101. 判断对称树 · Tree + 递归

    题面 判断给定二叉树是否对称. Note : empty tree is valid. 算法 1. 根节点判空,若空,则返回true;(空树对称) 2. 根节点不空,递归判断左右子树.如果左右孩子都空 ...