CF1217C
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的更多相关文章
随机推荐
- Java ShellSort
Java ShellSort /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternational ...
- IIs发布的项目无法打开问题
1/查看一下ISAPI筛选器,是否存在2.0,4.0,若缺少东西,就从新安装一下iis,存在某些程序没有被勾选,一般是asp.net3.5,asp.net4.0
- 获取类的描述信息 DescriptionAttribute
static void Main(string[] args) { var attrs = typeof(TestClass).GetCustomAttributes(typeof(System.Co ...
- Citrix ADC 12.1 / NetScaler 12
Citrix ADC 12.1 / NetScaler 12 参考 https://www.carlstalhood.com/netscaler-menu/netscaler-12/ Core – C ...
- pymsql及事务
MySQL知识点补充 1.去重 distinct select distinct name,age from t1; # 针对查找出来的结果整行(记录)进行去重,也就是相同行只保存一个 注意点:dis ...
- leetcode-102.层序遍历二叉树(正序)· BTree
题面 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to rig ...
- Dubbo:1
Dubbo能解决什么问题 怎么去维护url:通过注册中心去维护url(zookeeper.redis.memcache…). F5硬件负载均衡器的单点压力比较大:软负载均衡. 怎么去整理出服务之间的依 ...
- DNS理解
前言 英译汉的时候会掩盖很多本质,导致很多问题稀里糊涂,问的人不知道怎么说,回答的人也是答非所问. DNS是Domain Name System缩写,不是Domain Name Server,或者Do ...
- sk_buff内核api函数记录
1.alloc_skb() 上层协议要发送数据包的时候或网络设备准备接收数据包的时候调用 2.kfree_skb() 释放sk_buff结构体 3.skb_put() 在数据区的末端添加某协议的尾部 ...
- 阿里云服务器搭建gitlab
参考这位大神的博客 https://blog.csdn.net/zhaoyanjun6/article/details/79144175 安装邮件通知服务系统时,报了如下错误:send-mail: f ...