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. Dapper 入门

    中文文档连接:https://www.w3cschool.cn/dapperorm/dapperorm-toj931f2.html 官网文档连接:https://dapper-tutorial.net ...

  2. vue购物车动画效果

    使用动画的三个函数 v-on:before-enter="beforeEnter" v-on:enter="enter" v-on:after-enter=&q ...

  3. numpy相关使用

    相关学习资料 : numpy中文网 https://www.numpy.org.cn/ 1 numpy索引区间为左闭右开,第一个索引能取到,第二个索引取不到 索引内可加步长 如 import nump ...

  4. ASE19团队项目beta阶段Backend组 scrum7 记录

    本次会议于12月13日,19:30在微软北京西二号楼sky garden召开,持续10分钟. 与会人员:Hao Wang, Lihao Ran, Xin Kang 请假人员:Zhikai Chen 每 ...

  5. 【Hibernate】Hibernate关联关系的映射

    一.实体之间的关系 二.一对多的配置 2.1 第一步创建两个实体 2.2 第二步:配置映射文件 2.3 第三步:将映射放到核心配置文件中 三.级联 3.1 Hibernate中级联保存的效果 3.2 ...

  6. Codeforces 850C E. Arpa and a game with Mojtaba

    对每个数统计其素数因子各次方数的数,然后通过y = (x>>i) | (x&((1<<(i-1))-1)) 模拟delete x and add  to the lis ...

  7. Microsoft 中间语言

  8. Nginx系列1.2:nginx-rtmp流媒体服务器添加权限认证(推流权限和播放权限)

    用到的工具:OBS Studio(推流).nginx-rtmp流媒体服务器.VLC(拉取流播放) Nginx系列1:ubuntu16.04编译出适合自己的nginx服务器 Nginx系列1.1:ubu ...

  9. ios滑动回弹效果导致的穿透问题

    1 给样式中去除掉下面的css样式 -webkit-overflow-scrolling:touch;/* 当手指从触摸屏上移开,会保持一段时间的滚动 */ -webkit-overflow-scro ...

  10. 算法设计与分析 - 李春葆 - 第二版 - html v2

    1 .1 第 1 章─概论   1.1.1 练习题   1 . 下列关于算法的说法中正确的有( ).   Ⅰ Ⅱ Ⅲ Ⅳ .求解某一类问题的算法是唯一的   .算法必须在有限步操作之后停止   .算法 ...