CF1217C

题意:

给定一个01串,一个good01串的定义是这个01串所代表的二进制数字刚好等于它的长度,允许前导零,问这个01串当中有几个good子串

解法:

枚举每一段连续的 $ 0 $ ,$ num_0 $ 为 $ 0 $ 的个数,后面的数值为 $ res $ ,只要 $ res \geq len$ , $ len $ 是二进制下区间长度,并且 $ res \leq len+num_0 $ ,则会产生答案,因为前导 $ 0 $ 可以匹配,但如果这样不行,直接break。

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath> using namespace std; #define LL long long
#define N 200010 char ch[N];
int T,len; int main() {
scanf("%d",&T);
while(T--) {
scanf("%s",ch + 1);
len = strlen(ch + 1);
int num_0 = 0;
LL ans = 0LL;
for(int i = 1 ; i <= len ; i++) {
if(ch[i] == '0') num_0++;
else {
int res = 0;
for(int j = i ; j <= len && res <= num_0 + (j - i + 1) ; j++) {
res = 2 * res + ch[j] - '0';
if (res >= (j - i + 1) && res <= (num_0 + j - i + 1)) ans++;
else break;
}
num_0 = 0;
}
}
printf("%lld \n",ans);
}
//system("pause");
return 0;
}

CF1217C的更多相关文章

随机推荐

  1. c#入门学习笔记

    Hello World //打印语句 Console.WriteLine("Hello World"); //暂停 Console.ReadKey(); 数据类型 1.值类型 by ...

  2. 生成 excel 插件 Epplus

    最近做 .net core 项目 发现一个新的 生成excel 的插件 . 以前值用 aspose 或者 npio. 简介:Epplus是一个使用Open Office XML(Xlsx)文件格式,能 ...

  3. DRF框架中链表数据通过ModelSerializer深度查询方法汇总

    DRF框架中链表数据通过ModelSerializer深度查询方法汇总 一.准备测试和理解准备 创建类 class Test1(models.Model): id = models.IntegerFi ...

  4. python处理RSTP视频流

    python链接海康摄像头,并以弹出框的方式播放实时视频流, 这种方式是以弹出框的形式播放.本地测试可以,实际业务场景不建议使用.可以采用rtsp转rtmp的方式 @shared_task def p ...

  5. nodejs入门API之fs模块

    fs模块下的类与FS常量 fs模块下的主要方法 fs的Promise API与FileHandle类 一.fs模块下的类 1.1 fs.Dir:表示目录流的类,由 fs.opendir().fs.op ...

  6. go语言学习(基本数据类型)

    值类型: int/uint :根据系统确定是32还是64位.此外还有int8/uint8.int16/uint16.int32/uint32.int64/uint64 byte:字节型,相当于uint ...

  7. Linux命令——cat、more、less、head、tail

    cat 一次显示整个文件 -n:显示行号 -b :和 -n 相似,只不过对于空白行不编号 -s:当遇到有连续两行以上的空白行,就代换为一行的空白行 -E显示换行符 [root@localhost ~] ...

  8. 【问题】XShell连接不上Debian root用户

    类似文章:https://www.lianst.com/3231.html 修改此文件 重启ssh服务 ssh restart有问题,换一条命令OK 你的Linux发行版可能不一样,针对CentOS参 ...

  9. codeblocks glfw glew glm 配置

    Code in code::blocks Download Mini project in c,c++,c# ,OpenGL,GLUT,GLFW,windows form application so ...

  10. Linux下文档与目录结构

    目录分类 Linux目录结构的组织形式和Windows有很大的不同.首先Linux没有“盘(C盘.D盘.E盘)”的概念.已经建立文件系统的硬盘分区被挂载到某一个目录下,用户通过操作目录来实现磁盘读写. ...