【CF1073A】Diverse Substring(签到)
题意:给定一个由小写字母组成的串,要求找出一个子串使得其中出现最多的字母不超过它长度的一半下取整
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(签到)的更多相关文章
- Educational Codeforces Round 53 (Rated for Div. 2) A Diverse Substring
传送门 https://www.cnblogs.com/violet-acmer/p/10163375.html 题意: 给出串是多态的定义“长度为 n 的串 s ,当串 s 中所有字母出现的次数严格 ...
- Educational Codeforces Round 53 (Rated for Div. 2)
http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...
- 2018.12.21 浪在ACM 集训队第十次测试赛
浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...
- Codeforces-Educational Codeforces Round 53题解
写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya a ...
- Educational Codeforces Round 53 Editorial
After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...
- Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...
- Codeforces Edu Round 53 A-D
A. Diverse Substring 找普遍性(特殊解即可). 最简单的便是存在一个区间\([i, i + 1] (1 <= i < n)\),且$str[i] $ $ != str[ ...
- asp.net自动打卡、签到程序
目前公司上下班签到是上局域网的一个系统去点一下,由于打卡比较简单,所以有些快迟到的同事会找已经到公司的人帮忙代打卡.”以其它身份运行程序“来打开IE,去帮人打下,有时多几个人,也要这样操作,我感觉挺麻 ...
- C#串口通信程序实现无感知签到与答题
最近公司项目上线,之前利用串口通讯实现校牌的无感知签到程序, 项目上线以后刚刚好有时间把之前的出现的问题做下记录,废话不多,直接到主题 串口介绍: 串行接口简称串口,也称串行通信接口或串行通讯接口(通 ...
随机推荐
- 51nod——2478 小b接水(预处理 思维)
我本来想把每个谷都处理了,想了下觉得不好办.后来看其他人写的是处理每个位置,把每个位置可以接的水累加起来.整挺好. #include <bits/stdc++.h> using names ...
- MySql学习笔记04
复习 day01 数据库相关: create database db4 character set utf8; show databases; show create database db4; dr ...
- 常用自写函数[更新ing]
int gcd (int x, int y)//最大公约数 { return y == 0 ? x : gcd( y , x % y ); } int lcm(int x, int y)//最小公倍数 ...
- Oracle 数据库密码过期问题
(1)在CMD命令窗口中输入: sqlplus 用户名/密码@数据库本地服务名 as sysdba;(如:sqlplus scott/1234@oracle1 as sysdba; ...
- A1058 A+B in Hogwarts (20)(20 分)
A1058 A+B in Hogwarts (20)(20 分) If you are a fan of Harry Potter, you would know the world of magic ...
- Codeforces Round #460 (Div. 2)-A. Supermarket
A. Supermarket time limit per test2 seconds memory limit per test256 megabytes Problem Description W ...
- python之时间处理time模块
import time import datetime ''' print(time.time()) #返回当前系统时间戳 print(time.ctime()) #返回当前系统时间 print(ti ...
- 菜鸟学Linux - Hard Link与Symbolic Link
在学习Hard Link与Symbolic Link之前,需要大概了解一下inode与data block.在Linux的文件系统中,一个文件对应一个inode与若干个data block.inode ...
- TCP/IP网络编程之多进程服务端(二)
信号处理 本章接上一章TCP/IP网络编程之多进程服务端(一),在上一章中,我们介绍了进程的创建和销毁,以及如何销毁僵尸进程.前面我们讲过,waitpid是非阻塞等待子进程销毁的函数,但有一个不好的缺 ...
- 某面试公司出的面试题---用JS比较两个版本号高低
一天中午某个公司给我反馈的面试题,说,比较两个文件的版本号,然后我给发过去了,说我的代码不符合他的要求,o(╯□╰)o了var compareVersion = compareVersion||fun ...