cf B Bear and Strings
题意:给你一个字符串,然后找多少区间内含有“bear”,输出数目;
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; char str[];
int pos[]; int main()
{
while(scanf("%s",str)!=EOF)
{
int k=strlen(str);
memset(pos,,sizeof(pos));
int cnt=;
for(int i=; i+<=k; i++)
{
if(str[i]=='b'&&str[i+]=='e'&&str[i+]=='a'&&str[i+]=='r')
{
pos[cnt++]=i+;
}
}
int ans=;
int last=;
for(int i=; i<cnt; i++)
{
if(pos[i]-==)
{
ans+=(k-pos[i]); last=pos[i]-;
}
else
{
if(i==)
{
ans+=(pos[i]-+)*(k-pos[i]);
}
else
ans+=(pos[i]--last)*(k-pos[i]);
last=pos[i]-;
}
}
printf("%d\n",ans);
}
return ;
}
cf B Bear and Strings的更多相关文章
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces Round #226 (Div. 2)B. Bear and Strings
/* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...
- codeforces B. Bear and Strings 解题报告
题目链接:http://codeforces.com/problemset/problem/385/B 题目意思:给定一条只有小写英文组成的序列,需要找出至少包含一个“bear”的单词的子序列个数.注 ...
- cf D Bear and Floodlight
题意:有n个灯,每个灯有一个照亮的角度,现在从点(l,0)走到点(r,0),问这个人若一直被灯照着能最多走多远? 思路:状压dp,然后通过向量旋转求出点(dp[i[,0)与灯的坐标(p[j].x,p[ ...
- cf C Bear and Prime Numbers
题意:给你一个n,输入n个数,然后输入m,接下来有m个询问,每一个询问为[l,r],然后输出在区间内[l,r]内f(p)的和,p为[l,r]的素数,f(p)的含义为在n个数中是p的倍数的个数. 思路: ...
- 牛客 545A 小A与最大子段和 & CF 660F Bear and Bowling 4
大意: 给定序列$a$, 求选择一个子区间$[l,r]$, 使得$\sum\limits_{i=l}^r(i-l+1)a_i$最大. $n\le2e5, |a_i|\le 1e7$. 记$s[i]=\ ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- Codeforces Round #226 (Div. 2) B
B. Bear and Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- android ScrollView 充满屏幕
android:fillViewport=true ScrollView下面的组件如果有android:layout_height="fill_parent"或android:la ...
- iOS UIScrollView 你可能不知道的奇技淫巧
iOS 的 UIScrollView 可以说是十分强大,巧妙地运用它可以得到一些意想不到的效果.本文将举几个 ScrollView 不常见运用的例子. 自带信息应用 这个界面既可以上下卷动,也可以左右 ...
- Codeforces 231E - Cactus
231E - Cactus 给一个10^5个点的无向图,每个点最多属于一个环,规定两点之间的简单路:从起点到终点,经过的边不重复 给10^5个询问,每个询问两个点,问这两个点之间有多少条简单路. 挺综 ...
- Android屏幕图标尺寸规范
http://blog.csdn.net/dyllove98/article/details/9174229 . 程序启动图标:ldpi (120 dpi)小屏mdpi (160 dpi)中屏hdpi ...
- For and While loop choice.
/* Difference between 'for' and 'while'. We can transform everything between 'for' and 'while'. if t ...
- jquery 操作 checkbox
对checkbox的其他几个操作 1. 全选2. 取消全选3. 选中所有奇数4. 反选5. 获得选中的所有值 js代码 $("document").ready(function() ...
- eclipse build很慢的时候,有可能是js文件编译验证慢的问题
第一步: 去除eclipse的JS验证: 将windows->preference->Java Script->Validator->Errors/Warnings-> ...
- 【转】iOS开发UI篇—程序启动原理和UIApplication
原文 http://www.cnblogs.com/wendingding/p/3766347.html 一.UIApplication 1.简单介绍 (1)UIApplication对象是应用程 ...
- C# RSA加密/解密
RSA公钥加密算法是1977年由Ron Rivest.Adi Shamirh和LenAdleman在(美国麻省理工学院)开发的.RSA取名来自开发他们三者的名字.RSA是目前最有影响力的公钥加密算法, ...
- 颜色rgb
1.几种基本颜色的rgb 黑色:R.G.B(0.0.0) 白色:R.G.B(255.255.255) 红色:R.G.B(255.0.0) 绿色:R.G.B(0.255.0) 蓝色:R.G.B(0.0. ...