Educational Codeforces Round 72 (Rated for Div. 2) C题
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题的更多相关文章
- Educational Codeforces Round 72 (Rated for Div. 2) B题
Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...
- 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 ...
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D
https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...
- Educational Codeforces Round 72 (Rated for Div. 2)
https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...
- Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)
题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...
- 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 ...
- Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...
- 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 ...
随机推荐
- 开源定时任务框架Quartz(二)
概述 上一篇文章完成了第一个Quartz程序的编写,这篇从Quartz中的几个重要对象来更深一层认识Quartz框架. Job和JobDetail Job是Quartz中的一个接口,接口下只有exec ...
- Demonstration(CodeForces-191B)【贪心】
题目链接:https://vjudge.net/problem/CodeForces-191B 题意:过于繁琐,略 思路:真·神级贪心题 首先我们可以想到的是,为了在k天内选到最靠前的城市,我们要想办 ...
- windows自动化测试 (python)
装插件 pywinauto 命令 pip install --upgrade pywinauto 最简单的一个例子,中文环境下 from pywinauto.application impor ...
- Python之装饰器笔记
概述: 用于管理和增强函数和类行为的代码 提供一种在函数或类定义中插入自动运行代码的机制 特点 更明确的语法.更高的代码可维护性.更好的一致性 编写 函数基础: 将函数赋给变量.将函数作为参数传递. ...
- 小程序文案过长,‘收起/展开’文字,createSelectorQuery 获取节点成功,boundingClientRect 返回信息null
问题描述: wxml中id是动态生成的. 获取节点信息是在onReady生命周期函数内延时500ms执行的,select(id)可以获取全部节点信息,boundingClientRect (rect) ...
- s5p6818 Overview
S5P6818: 64bit Octa-Core, High Performance, Advanced 3D Graphics, Full-HD Multimedia Video, A53 Core ...
- Oracle VIP说明
本篇文档,描述说明VIP的作用 1.VIP全称 virtual ip 虚拟IP 2.Oracle为啥要搞个VIP 3.两节点RAC,集群单个节点故障关闭后,VIP漂移否继续对外提供服务 一.模拟RAC ...
- The Heaviest Non-decreasing Subsequence Problem
最长非递减子序列变形题,把大于等于10000的copy五次放回去就可以了 ac代码: #include <cstdio> #include <cstring> #include ...
- java01_简介_开发环境
JAVA的前世今生 美国SUN(Stanford University Network)公司,在中国大陆的正式中文名为"太阳计算机系统(中国)有限公司",在中国台湾的正式中文名为& ...
- VBA教程(一)
VBA代表Visual Basic for Applications,它是一个来自Microsoft的事件驱动的编程语言. 现在它主要用于Microsoft Office应用程序,如MSExcel,M ...