题意:给定一个由小写字母组成的串,要求找出一个子串使得其中出现最多的字母不超过它长度的一半下取整

n<=1e3

思路:

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 11000
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1) int s[N][];
char ch[N]; int main()
{
int n;
scanf("%d",&n);
scanf("%s",ch+);
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++) s[i][j]=s[i-][j];
s[i][ch[i]-'a'+]++;
}
int x=;
int y=;
for(int i=;i<=n;i++)
for(int j=i;j<=n;j++)
if(x+y==)
{
int len=j-i+;
int tmp=;
for(int k=;k<=;k++) tmp=max(tmp,s[j][k]-s[i-][k]);
if(tmp<=len/){x=i; y=j;}
} if(x+y>)
{
printf("YES\n");
for(int i=x;i<=y;i++) printf("%c",ch[i]);
}
else printf("NO\n");
return ;
}

【CF1073A】Diverse Substring(签到)的更多相关文章

  1. Educational Codeforces Round 53 (Rated for Div. 2) A Diverse Substring

    传送门 https://www.cnblogs.com/violet-acmer/p/10163375.html 题意: 给出串是多态的定义“长度为 n 的串 s ,当串 s 中所有字母出现的次数严格 ...

  2. Educational Codeforces Round 53 (Rated for Div. 2)

    http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...

  3. 2018.12.21 浪在ACM 集训队第十次测试赛

     浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...

  4. Codeforces-Educational Codeforces Round 53题解

    写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya a ...

  5. Educational Codeforces Round 53 Editorial

    After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...

  6. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  7. Codeforces Edu Round 53 A-D

    A. Diverse Substring 找普遍性(特殊解即可). 最简单的便是存在一个区间\([i, i + 1] (1 <= i < n)\),且$str[i] $ $ != str[ ...

  8. asp.net自动打卡、签到程序

    目前公司上下班签到是上局域网的一个系统去点一下,由于打卡比较简单,所以有些快迟到的同事会找已经到公司的人帮忙代打卡.”以其它身份运行程序“来打开IE,去帮人打下,有时多几个人,也要这样操作,我感觉挺麻 ...

  9. C#串口通信程序实现无感知签到与答题

    最近公司项目上线,之前利用串口通讯实现校牌的无感知签到程序, 项目上线以后刚刚好有时间把之前的出现的问题做下记录,废话不多,直接到主题 串口介绍: 串行接口简称串口,也称串行通信接口或串行通讯接口(通 ...

随机推荐

  1. grep过滤目录或文件方法

    在使用grep在指定目录下查找包含指定字符串的文件是,我们想过滤(即不递归查询指定目录)时!可以使用 –exclude-dir 参数 单个目录实例 搜索.目录但不搜索在.目录下的.svg目录中包含&q ...

  2. SAP系统管理中常见问题解答(转载)

    1.如何查看SAP系统的位数? system——status看 Platform ID Platform 32-bit 64-bit --------------------------------- ...

  3. Spring Cloud 入门 Eureka-Server服务注册

    这里就不介绍怎么创建springboot项目了,可以查看我前面的博客 Spring Cloud Eureka Spring Cloud Eureka是Spring Cloud Netflix项目下的服 ...

  4. vue 判断是否登录,未登录跳转到登录页

    网页一进入判断是否登录,未登录跳转到登录页面 router.js export default new Router({ routes: [ { path: '/', name: 'HelloWorl ...

  5. 第二章JavaScript 函数和对象

    1 JavaScript 函数 1.1 声明函数的方式 function 关键字 匿名函数方式(表达式方式) Function 构造函数方式 1.2 参数问题 形参和实参数量问题 可选形参(参数默认值 ...

  6. thinkphp 5数据库操作

    1.原生sql $options=Db::table('__MALL_POST__') ->alias('m') ->join('__MALL_CATEGORY_VALUE__ v','m ...

  7. [Uva623]500!(高精)

    Description 求N! \(N \leq 1000\) Sample Input 10 30 50 100 Sample Output 10! 3628800 30! 265252859812 ...

  8. Spring核心技术(十四)——ApplicationContext的额外功能

    在前文的介绍中我们知道,org.springframework.beans.factory包提供了一些基本的功能来管理和控制Bean,甚至通过编程的方式来实现.org.springframework. ...

  9. np.newaxis()用法

    这个是liaspace函数 这个是np.newaxis的用法,增加维度,写一个表示增加一维,两个表示增加2维2位置的:号是对a的取值范围,如果把np.newaxis作为第一个参数是对行增加维度,作为第 ...

  10. Python框架之Django学习笔记(三)

    开始一个项目 第一次使用 Django,必须进行一些初始化设置工作. 新建一个工作目录,例如 D:\tool\python\Python27\workspace\djcode,然后进入该目录. 转到创 ...