Educational Codeforces Round 53 (Rated for Div. 2)

A. Diverse Substring(前缀和)

题意:给一个字符串,找出一个子串满足该子串中每个字母出现的次数不超过子串的长度/2,字符串的长度n<1000.

题解:n方枚举子串的起点和终点,对于每个字母建一个前缀和就能知道在任意一个字串中每个字母出现的个数了。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char s[1010];
int n;
int num[30][1010];

int main(){
    scanf("%d", &n);
    scanf("%s", s+1);
    for(int i = 1; i<=n; i++){
        for(int k = 0; k<27; k++){
            num[k][i] = num[k][i-1];
        }
        num[s[i]-‘a‘][i] = num[s[i]-‘a‘][i-1]+1;
    }
    int l = -1, r = -1;
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=i; j++){
            bool flag = true;
            for(int k = 0; k<28; k++){
                if(num[k][i]-num[k][j-1]>(i-j+1)/2){
                    flag = false;
                    break;
                }
            }
            if(flag == true){
                l = j; r = i;
            }
        }
    }
    if(l!=-1 && r!=-1){
        cout<<"YES"<<endl;
        for(int i = l; i<=r; i++){
            cout<<s[i];
        }
        cout<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

    return 0;
}

原文地址:https://www.cnblogs.com/grimcake/p/9859052.html

时间: 2024-11-01 09:55:07

Educational Codeforces Round 53 (Rated for Div. 2)的相关文章

Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, i

Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k种 思路 这题一看就是个数位dp的模板题,但是由于以前没有完全理解数位dp加上xjb套模版,导致样例都没算出来 一开始这样定义状态 dp[i][j] 代表第cnt-i(高位到低位)位,cnt~i状态为j的总和 一直记录当前数字的数值,到边界的时候返回加到答案中,但是由于这样定义状态会导致一个状态对应

Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem

题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感觉之前写的svt什么玩意) //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) //#pragma GCC optimize("unroll-loops") //#pragma comm

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm