Codeforces 385B Bear and Strings

题目链接: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;
时间: 2024-08-01 22:35:34

Codeforces 385B Bear and Strings的相关文章

Codeforces 360C Levko and Strings dp

题目链接:点击打开链接 题意: 给定长度为n的字符串s,常数k 显然s的子串一共有 n(n-1)/2 个 要求找到一个长度为n的字符串t,使得t对应位置的k个子串字典序>s #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<set> using namespace std; #

[2016-03-23][codeforces][560][D][Equivalent Strings]

时间:2016-03-23 14:15:39 星期三 题目编号:[2016-03-23][codeforces][560][D][Equivalent Strings] 题目大意:定义两个字符串相等方式,给出两个字符串,问是否相等 分析:递归判断即可 遇到的问题:长度为奇数的字符串一定不相等 #include <iostream> #include <string> using namespace std; int issame(string str1,string str2){

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

题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,现在从中选定一个字符串为答案串,你不知道答案串是哪个,但是可以通过询问来确定, 每次询问一个位置上字符为多少.现在你询问的每个位置的概率是相同的,(问过的位置不会再问),求询问次数的期 望. 解题思路:因为字符串长度不会大于20,所以用二进制表示询问了哪些位置,C[s]即为询问s的位置可以确定多少个字 符串.这步不能通过枚举s,然后判断处理,复杂度为o(2^20 * 20 * 50),太高.可

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

Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时

codeforces 682D Alyona and Strings

D. Alyona and Strings After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she

codeforces 657C - Bear and Contribution [想法题]

题目链接: http://codeforces.com/problemset/problem/657/C -------------------------------------------------------------------------------------------------------- 题目的特别之处在于只有 $+1$ $+5$ 这两种操作 我们要考虑如何利用这个条件 多想一下后可以发现 如果最优解的目标值为$x($将至少$k$个人的值增加到$x)$ 那么一定存在一个

CodeForces 573A Bear and Poker

题目链接:http://codeforces.com/problemset/problem/573/A 题目大意:此题要求一组数中的元素乘以2或者乘以3后得到的数都一样,其实就是判断这些数除去2和3这些因子后剩下的因子都是一样的即可. AC代码: #include <cstdio> #include <cmath> #include <cstring> #include <iostream> using namespace std; #define M 10

Codeforces A - Bear and Prime 100(交互题)

A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表:{2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49},询问19次,如果能被整出两次以上,说明是合数,否则是质数. #include<bits/stdc++.h> using namespace std; #define ll long long

Codeforces 679B - Bear and Tower of Cubes

679B - Bear and Tower of Cubes 题目大意:一个数x定义一种拆分方式,每次拆分取最大的a 且 a^3<=x,x减去a^3,之后重复同样的操作,直到 x变为0.给你一个数m( m<=1e15 ),让你取一个数q<=m,q能执行的操作数在小于等于m的数里面最大,且在操作数 最大的里面,值是最大的. 感觉这种思维题就是特别难.... 思路:设a为当前小于等于m的最大立方数.则对于当前的 m 我们有两种情况要考虑,第一种是res1=m-a^3 第二种是不想减去a^3,