codeforces 165C Another Problem on Strings 双指针
来源:互联网 发布:软件使用 编辑:程序博客网 时间:2024/05/18 01:02
题意:求对于给定01字符串,有多少个子串,其恰好包含了k个1
双指针,把每个1都找出来,统计这个1之后有多少个0
然后用乘法原理计算
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define rep(i, j, k) for(int i = j; i <= k; i++) using namespace std; typedef long long lo;char buff[1001000];lo l[1001000];int main() {lo sum=0,k, count=0, ptr=0;cin >> k >> buff;lo n=strlen(buff);for (lo i=0;i<n;i++) {l[ptr]++;if (buff[i]=='1') ptr++;}l[ptr]++;if (k==0) for (lo i=0;i<=ptr;i++)(count+=(l[i]-1)*(l[i]-2)/2 + l[i]-1);else for (lo i=0;i+k<=ptr;i++)count+=(l[i])*(l[i+k]);cout << count;return 0;}
0 0
- codeforces 165C Another Problem on Strings 双指针
- CodeForces 165C - Another Problem on Strings
- CodeForces 165C - Another Problem on Strings
- codeforces-165C-Another Problem on Strings
- Codeforces 165C Another Problem on Strings 【二分】
- CodeForces 165C Another Problem on Strings(公式推导)
- Another Problem on Strings CodeForces
- codeforce 165C Another Problem on Strings
- Codeforces Round #112 (Div. 2) C Another Problem on Strings
- Codeforces Round #112 (Div. 2) C. Another Problem on Strings
- Codeforces Round #112 (Div. 2) C Another Problem on Strings
- Codeforces 165C Another Problem On Strings 尺取 Or 前缀和
- codeforces 165-C. Another Problem on Strings(计数+尺取)
- codeforces 之 Another Problem on Strings
- Another Problem on Strings
- codeforces Another Problem on Strings 记录一个不慎
- cf165c Another Problem on Strings
- C. Another Problem on Strin
- 决策树
- Java中实现Comparable接口和Comparator接口的排序算法效率比较
- 腾讯Tencent
- 魔都一月记
- ios属性和实例变量
- codeforces 165C Another Problem on Strings 双指针
- [leetcode]Maximum Subarray
- UVa1583 - Digit Generator 生成元 (java版本)
- Java中Object类的equals方法
- IP问题(1)
- BGRABitmap图像操作6:前面的长方形改成既有圆角又有尖角
- ORACLE索引的作用及用法
- Linux 下编译C语言
- Atlantis(离散化)