C - The Number Of Good Substrings CodeForces - 1217C

 

 

 

 


#include <bits / STDC H ++.> a using namespace std; typedef Long Long LL; / * give you only a string of 0s and 1s, the binary values ask you how many children to meet length equal to the string substring I did not know how violence, then I wanted to direct aid under the front and from the binary value obtained beg but still can not, tle now the idea is to go directly to position 1, and then ask him how many left leading 0, 1 later this extension, it is not enough with leading 0, as to enumerate all 1 so there is no omission, and do so from the beginning up to the length of the back extension 18 is greater than its 18 << 1 the * / const int MAXN 2E5 + = 10 ; int DIS = 18 is ; char S [MAXN]; int main () { int T; Scanf ( " % D " , & T); the while (T--) { scanf("%s",s); int sum=0; int len=strlen(s); int pre=0; for(int i=0; i<len; i++) { if(s[i]=='0') pre++; else { int r=i; int cnt=1; for(int j=0; j<dis; j++) { if(cnt<=pre+(r-i+1)) sum++; if(r==len-1) break; cnt=cnt*2+(s[++r]-'0'); } pre=0; } } printf("%d\n",sum); } return 0; }

 

Guess you like

Origin www.cnblogs.com/zhangzhenjun/p/11616332.html