题目链接:Codeforces 385B Bear and Strings

记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重。

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int MAX_N = 5000 + 100; char str[MAX_N]; struct Node
{
int l, r;
};
Node node[MAX_N / 3]; int main()
{
scanf("%s", str);
int len = strlen(str);
int cnt = 0;
for(int i = 0; i < len - 3; i++)
{
if(str[i] == 'b' && str[i + 1] == 'e' && str[i + 2] == 'a' && str[i + 3] == 'r')
{
node[cnt].l = i;
node[cnt].r = i + 3;
cnt++;
}
}
int res = 0;
int r ,l , last = 0;
for(int i = 0; i < cnt; i++)
{
l = node[i].l - last;
r = len - node[i].r - 1;
res += l;
res += r;
res += (l * r);
res++;
last = node[i].l + 1;
}
printf("%d\n", res);
return 0;

Codeforces 385B Bear and Strings的更多相关文章

  1. codeforces B. Bear and Strings 解题报告

    题目链接:http://codeforces.com/problemset/problem/385/B 题目意思:给定一条只有小写英文组成的序列,需要找出至少包含一个“bear”的单词的子序列个数.注 ...

  2. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

  3. Codeforces 482C Game with Strings(dp+概率)

    题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...

  4. Codeforces 680D Bear and Tower of Cubes 贪心 DFS

    链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...

  5. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  6. [Codeforces 639F] Bear and Chemistry (Tarjan+虚树)(有详细注释)

    [Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q ...

  7. Codeforces Round #226 (Div. 2)B. Bear and Strings

    /* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...

  8. Codeforces 791C. Bear and Different Names 模拟构造

    C. Bear and Different Names time limit per test:1 second memory limit per test:256 megabytes input:s ...

  9. Codeforces 791B Bear and Friendship Condition(DFS,有向图)

    B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...

随机推荐

  1. 解析php混淆加密解密的手段,如 phpjm,phpdp神盾,php威盾

    原文 解析php混淆加密解密的手段,如 phpjm,phpdp神盾,php威盾 php做为一门当下非常流行的web语言,常常看到有人求解密php文件,想当年的asp也是一样.一些人不理解为什么要混淆( ...

  2. HDU 4611 Balls Rearrangement (数学-思维逻辑题)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4611 题意:给你一个N.A.B,要你求 AC代码: #include <iostream> ...

  3. nginx 源码安装

    安装环境: 操作系统:Ubuntu 12.04 Nginx:     V1.4.2 PCRE:    V8.33 zlib:         V1.2.8 下载上述源包到当前用户主目录(本机:/hom ...

  4. kafka web console安装

    貌似非常多小伙伴都不能成功打包,共享下之前打包的文件: http://pan.baidu.com/s/1sjkE37J ======== kafka自己竟然没有还一个Web管理界面.. 这里有个第三方 ...

  5. 每天进步一点点——Linux磁盘管理LVM与RAID

    转载请注明出处:http://blog.csdn.net/cywosp/article/details/38965799 1. 传统磁盘管理问题 当分区大小不够用时无法扩展其大小,仅仅能通过加入硬盘. ...

  6. JVM学习03_new对象的内存图讲解,以及引出static方法(转)

    目录 -=-讲解对象创建过程中,-=-堆内存和栈内存的情况 -=-构造函数对类对象的成员变量的初始化过程 -=-构造函数出栈 -=-类的方法在不访问类对象的成员变量时造成的内存资源浪费怎么解决? -= ...

  7. nutch搏斗之一

    nutch搏斗之一 问题描述: 在用nutch1.0做generate 包括5亿url的crawldb时,它默认按照64M分块,分成777个map task,在运行的后期出现 Could not fi ...

  8. Hadoop里的Partitioner

    人们对于Mapreduce程序刚開始时都觉得仅仅须要一个reduce就够了. 毕竟,在你处理数据之前一个reducer已经把数据都分好类了,有谁不喜欢分好类的数据呢. 可是这样我们就忽略了并行计算的优 ...

  9. 设计模式学习一:strategyPattern

    #ifndef STRATEGYPATTERN_H_#define STRATEGYPATTERN_H_#include<iostream>using namespace std; //策 ...

  10. Welcome Docker to SUSE Linux Enterprise Server【水平有限,中英对比,求纠错】

      原文:Welcome Docker to SUSE Linux Enterprise Server Lightweight virtualization is a hot topic these ...