Codeforces Round #226 (Div. 2) B
1 second
256 megabytes
standard input
standard output
The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring.
String x(i, j) contains string "bear", if there is such index k (i ≤ k ≤ j - 3), that sk = b, sk + 1 = e, sk + 2 = a, sk + 3 = r.
Help the bear cope with the given problem.
The first line contains a non-empty string s (1 ≤ |s| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
bearbtear
6
bearaabearc
20
In the first sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, 10), (6, 11), (7, 10), (7, 11).
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std; int gao(string s){
vector< pair<int,int> >seg ;
vector< pair<int,int> >::iterator it ;
seg.clear() ;
int i ,Len = s.length() ,L ,R ,ans = ,reL ;
for(i = ; i <= Len - ; i++){
if(s[i]=='b'&&s[i+]=='e'&&s[i+]=='a'&&s[i+]=='r')
seg.push_back(make_pair(i+,i++)) ;
}
if(seg.size() == )
return ;
it = seg.begin() ;
reL = L = it->first ;
R = it->second ;
ans += L * (Len - R +) ;
for(it++; it != seg.end() ; it++){
L = it->first ;
R = it->second ;
ans += (L - reL) * (Len - R + ) ;
reL = L ;
}
return ans ;
} int main(){
string s ;
while(cin>>s){
cout<<gao(s)<<endl ;
}
return ;
}
Codeforces Round #226 (Div. 2) B的更多相关文章
- Codeforces Round #226 (Div. 2 )
这次精神状态不怎么好,第一题的描述看得我就蛋疼...看完就速度写了~~~最终fst了%>_<%,第二题写复杂了,一直WA pretest 3,然后就紧张,导致精神更不好了,一直纠结在第二题 ...
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
/* 可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数, 然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数. */ #include <stdio.h ...
- Codeforces Round #226 (Div. 2)A. Bear and Raspberry
/* 贪心的找到相邻两项差的最大值,再减去c,结果若是负数答案为0. */ 1 #include <stdio.h> #define maxn 105 int num[maxn]; int ...
- Codeforces Round #226 (Div. 2)B. Bear and Strings
/* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...
- 【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight
读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm& ...
- Codeforces Round #226 (Div. 2) C题
数论好题 题目要求:求给定序列的素因子如果在给定区间内该数字个数加1; 思路:打表时求出包含给素数因子的数的个数,详见代码 1 #include<cstring> +; scan ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- java面试准备之基础排序——冒泡与选择排序
选择排序: [java] public void select(int[] arr){ for(int i=0;i<arr.length;i++){ ...
- android属性之excludeFromRecents -- clearTaskOnLaunch 隐身意图 启动activity
这个可以 用android 任务中app 隐藏起来 android属性之clearTaskOnLaunch 此属性是 每次启动app时都会进入 根目录中 android:clearTask ...
- MAC机中安装ruby环境--转载
http://www.cnblogs.com/pingfan1990/p/4957162.html
- 点击含下拉菜单的列表/表单按钮:通过JS创建虚拟按钮并点击
${JsCode} | Get Element Attribute | XPATH=//table[@class='mnubar']//tr//td//span[text()='${MenuArr[0 ...
- JQuery正则验证
比较常用的: function checkIshanzi(s) { //var patrn = /^[\u2E80-\u9FFF]$/; //Unicode编码中的汉字范围 /[^\x00-\x80] ...
- mysql常用&实用语句
Mysql是最流行的关系型数据库管理系统,也是目前最常用的数据库之一,掌握其常用的操作语句是必不可少的. 下面是自己总结的mysqp常用&实用的sql语句: 1.mysql -u root - ...
- 国内较快的maven镜像
原文网址:http://www.cnblogs.com/dingyingsi/p/3856456.html 国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以 ...
- Thrift 个人实战--初次体验Thrift
前言: Thrift作为Facebook开源的RPC框架, 通过IDL中间语言, 并借助代码生成引擎生成各种主流语言的rpc框架服务端/客户端代码. 不过Thrift的实现, 简单使用离实际生产环境还 ...
- A Brief Introduction to Markovs Chains
本文译自A Brief Introduction to Markovs Chains 译者按: 前面一篇文章讲的是蒙特卡洛积分,也就是通过生成符合特定分布的随机变量来近似计算积分值,例如: \(E = ...
- python thread 多线程
thread 模块在python3中改为_thread,网上的各种帖子都说不建议新手使用thread,好吃不好吃总得尝尝看. import _thread def print_num(): for i ...