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. SAS学习笔记11 SAS宏

    宏是一个被储存的文本,用一个名字识别它.最简单的宏就像一个宏变量一样工作,但复杂的宏可以完成许多宏变量不能做的事. 定义宏的语句格式为: %macro 宏名称: 宏文本 %mend <宏名称&g ...

  2. Vs code 下设置python tasks.json

    { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.jso ...

  3. QMap里面的值任然是一个QMap,在做循环插入的时候需要记得清空。

    这个问题是我以前的一个问题,当时由于有其他的事情去处理就忘记了,前段时间我的项目要进行集成测试了,为了避免这个缺陷,只能再把这个问题想起来了,再进行解决.有很多问题你觉得不应该发生,其实很多时候都是逻 ...

  4. opencv-03--图像的算术运算

    图像的算术运算 Mat类把很多算数操作符都进行了重载,让它们来符合矩阵的一些运算,如果+.-.点乘等. 下面我们来看看用位操作和基本算术运算来完成colorReduce程序,它更简单,更高效. 将25 ...

  5. VBA连接操作符

    VBA支持以下连接运算符. 假设变量A=5,变量B=10,则 - 运算符 描述 示例 + 将两个值添加为变量,其值是数字 A + B = 15 & 连接两个值 A & B = 510 ...

  6. UMI.js开发知识总结

    五分钟掌握最小知识体系 本文阅读时间大概为5分钟,但是能让你了解基于UMI和DVA构建项目的最小知识体系,你可以粗略的浏览一下本文所提到的知识,在后续的讲解中都会多次重复提起,保证学习效率.由于现在前 ...

  7. 关于Http协议与TCP协议的一些简单理解

    TCP协议对应于传输层,而HTTP协议对应于应用层,从本质上来说,二者没有可比性.Http协议是建立在TCP协议基础之上的,当浏览器需要从服务器获取网页数据的时候,会发出一次Http请求.Http会通 ...

  8. c# Format() 方法

  9. java中的管程

    前言 ​ 并发编程这个技术领域已经发展了半个世纪了,相关的理论和技术纷繁复杂.那有没有一种核心技术可以很方便地解决我们的并发问题呢?这个问题如果让我选择,我一定会选择管程技术.Java 语言在 1.5 ...

  10. 03 WIndows编程——手绘函数调用过程

    源码 #include<Windows.h> #include<stdio.h> int MessageBoxPrint(char *szFormat, ...); int W ...