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 ...
随机推荐
- find程序实现
一个简单的查找字符串匹配 #include <stdio.h> #include <string.h> #define MAXLINE 1000 int getline(cha ...
- 1262: 谁不爱打牌(Java)
WUSTOJ 1262: 谁不爱打牌 转自 断-肠-人的博客 Java代码在文末 Description BobLee最近在复习考研,但是他也喜欢打牌(有谁不爱玩牌呢?).但是作为一名ACMER,斗地 ...
- 1261: 单位转换(Java)
WUSTOJ 1261: 单位转换 参考资料 数字字符串拆分--百度知道 Description BobLee最近在复习考研,在复习计算机组成原理的时候,遇到了一个问题.就是在计算机存储里面的单位转换 ...
- [eclipse]UML之AmaterasUML 插件
软件体系结构分析软件设计模式要求给出相应设计模式源码对应的UML类图,在此之前我安装过一种UML插件,可以自动生成一个源码包对应的UML类图,但是重装过系统,所以软件包括eclipse都重新下载了新的 ...
- C# DateTime Subtract
DateTime start = DateTime.Now.AddDays(-20); DateTime end = DateTime.Now; TimeSpan ts = end.Subtract( ...
- (十七)Activitivi5之组任务分配
一.需求分析 我们在实际业务开发过程中,某一个审批任务节点可以分配一个角色(或者叫做组),然后属于这个角色的任何一个用户都可以去完成这个任务节点的审批 二.案例 2.1 方式一:直接流程图配置中写死 ...
- (九)Redis之集群概述(转)
本章转自: http://blog.java1234.com/blog/articles/325.html Redis Cluster与Redis3.0.0同时发布,以此结束了Redis无官方集群方案 ...
- (十三)SpringBoot之Spring-Data-Jpa(二)CRUD实现以及添加自定义方法
一.jpa中添加自定义方法 http://blog.csdn.net/qq_23660243/article/details/43194465 二.案例 1.3 引入jpa依赖 <depende ...
- Linux装好系统之后配置环境
1.配置IP地址vi /etc/sysconfig/network-scripts/ifcfg-eth0 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static D ...
- vue获取当前路由
完整url可以用 window.location.href路由路径可以用 this.$route.path路由路径参数 this.$route.params 例如:/user/:id → /user/ ...