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

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. 【转】C++ 标准库值操作迭代器的常见函数

    迭代器是C++标准库中的重要组件,特别是在容器内部,没有迭代器,容器也就无所谓存在了. 例如:vector容器简而言之就是3个迭代器 start finish 以及end_of_storage vec ...

  2. 【搜索】【入门】洛谷P1036 选数

    题目描述 已知 n个整数x1​,x2​,…,xn​,以及1个整数k(k<n).从nn个整数中任选kk个整数相加,可分别得到一系列的和. 例如当n=4,k=3,4个整数分别为3,7,12,19时, ...

  3. ES6箭头函数基本用法

    ES6箭头函数基本用法 ``` window.onload = function(){ alert(abc); } //箭头函数 window.onload = ()=>{ alert(&quo ...

  4. JZOJ 5775. 【NOIP2008模拟】农夫约的假期

    5775. [NOIP2008模拟]农夫约的假期 (File IO): input:shuru.in output:shuru.out Time Limits: 1000 ms  Memory Lim ...

  5. Pycharm中F4查看函数的相关小BUG

    我们都知道在Pycharm中我们要快速查看某个函数或者模块的源码,可以在该函数上按F4快捷键,其可以打开源码相关的.py文件,这两天偶然发现起打开的文件不一定是对的. -代码如下: import os ...

  6. Java模拟音乐播放器 暂停与重新播放——线程如何控制另外一个线程的状态

    package com.example.Thread; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEve ...

  7. 排查和处理一台被攻击的linux系统及其事后分析

    11:40 2018/3/16 发现最近几天服务器流量异常的大,检查了系统命令发现命令最近的修改时间很近,检查dns配置也发现了异常的dns服务器地址. 考虑到事态的严重性,铲掉这个系统重新搭建. 事 ...

  8. 新博客 http://kunyashaw.com/

    感谢博客园. 请关注我的新博客: http://kunyashaw.com/

  9. mongo命令

    安装mongo http://docs.mongodb.org/master/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux/ 启动 ...

  10. var、let、const与JavaScript变量/常量的定义

    早期的JavaScript中,声明变量只能使用var关键字定义变量,并没有定义常量的功能.通过var关键字定义的变量,其作用域只能函数级或是全局作用域,并没有块级作用域.ES6(ECMAScript ...