传送门

https://www.cnblogs.com/violet-acmer/p/10163375.html

题意:

  给出串是多态的定义“长度为 n 的串 s ,当串 s 中所有字母出现的次数严格 ≤ n/2,就称此串是多态的”。

  求某串 s 是否含有多态的字串,如果含有,输出"YES",并输出此串,反之,输出"NO"。

题解:

  开局连 wa 五发,读错题意了,难受。

  比赛时提交的代码是暴力过的,就是判断长度为 len 的字串是否为多态串,枚举所有可能。

  用了树状数组稍加优化了一番,代码如下:

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e3+; int n;
char s[maxn];
//'a' <- 0,'b' <- 1,依次类推
//bit[i][j] : 前j个字符字母i出现的次数
int bit[][maxn];
void Add(int t,int i)
{
while(t <= n)
{
bit[i][t]++;
t += (t&-t);
}
}
int Sum(int t,int i)
{
int res=;
while(t > )
{
res += bit[i][t];
t -= (t&-t);
}
return res;
}
bool isSat(int a,int b)
{
for(int i=;i < ;++i)
if(Sum(b,i)-Sum(a-,i) > ((b-a+)>>))
return false;
return true;
}
void Solve()
{
mem(bit,);
for(int i=;i <= n;++i)
Add(i,s[i]-'a');
for(int len=;len <= n;++len)
{
for(int i=;i+len- <= n;++i)
{
int j=i+len-;
if(isSat(i,j))
{
printf("YES\n");
for(int k=i;k <= j;++k)
printf("%c",s[k]);
printf("\n");
return ;
}
}
}
printf("NO\n");
}
int main()
{
scanf("%d%s",&n,s+);
Solve();
return ;
}

  然后,今天整理这道题的时候,突然想到,如果含有两个连续的不同字符,那这个子串肯定是多态的啊,so,写了个短短的代码。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e3+; int n;
char s[maxn]; void Solve()
{
for(int i=;i <= n;++i)
{
if(s[i] != s[i-])
{
printf("YES\n");
printf("%c%c\n",s[i-],s[i]);
return ;
}
}
printf("NO\n");
}
int main()
{
scanf("%d%s",&n,s+);
Solve();
return ;
}

Educational Codeforces Round 53 (Rated for Div. 2) A Diverse Substring的更多相关文章

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

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

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

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

  3. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)

    题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...

  4. [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

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

    https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...

  6. 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 mem ...

  7. 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即可.(感 ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair

    题意:一个人  有T块钱 有一圈商店 分别出售 不同价格的东西  每次经过商店只能买一个  并且如果钱够就必须买 这个人一定是从1号店开始的!(比赛的时候读错了题,以为随意起点...)问可以买多少个 ...

  9. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot

    题意:给出一段操作序列 和目的地 问修改(只可以更改 不可以删除或添加)该序列使得最后到达终点时  所进行的修改代价最小是多少 其中代价的定义是  终点序号-起点序号-1 思路:因为代价是终点序号减去 ...

随机推荐

  1. 莫烦keras学习自修第三天【回归问题】

    1. 代码实战 #!/usr/bin/env python #!_*_ coding:UTF-8 _*_ import numpy as np # 这句话不知道是什么意思 np.random.seed ...

  2. Vue之computed计算属性

    demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...

  3. LODOP安装参数 及静默安装

    在cmd命令里里静默安装lodop(c-lodop不能静默安装),本人的安装文件放在D:\lodopdownload\3060\Lodop6.224_Clodop3.060,如下所示: lodop静默 ...

  4. mysql-语法大全

    DDL语句 库 创建 create database 库名 charset utf8; 删除 drop database 库名; 修改 alter database 库名 charset latin; ...

  5. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2

    A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后 ...

  6. Configure an PPTP Server on Debian

    安装PPTP apt-get update apt-get upgrade apt-get install iptables pptpd vim 设置并修改配置文件vim /etc/pptpd.con ...

  7. 【题解】 bzoj1135: [POI2009]Lyz (线段树+霍尔定理)

    题面戳我 Solution 二分图是显然的,用二分图匹配显然在这个范围会炸的很惨,我们考虑用霍尔定理. 我们任意选取穿\(l,r\)的号码鞋子的人,那么这些人可以穿的鞋子的范围是\(l,r+d\),这 ...

  8. JLOI2015 DAY2 简要题解

    「JLOI2015」骗我呢 题意 问有多少个 \(n \times m\) 的矩阵 \(\{x_{i, j}\}\) 满足 对于 \(\forall i \in [1, n], j \in [1, m ...

  9. Dynamic CRM 2015学习笔记(4)修改开发人员资源(发现服务、组织服务和组织数据服务)url地址及组织名

    在azure vm上安装了CRM 2015后 Dynamic CRM 2015学习笔记(1)Azure 上安装 CRM 2015, 发现了一个问题,那就是在设置 ->自定义项 –> 开发人 ...

  10. 让自己的网站实现在线编辑office文档

    我们可以通过Office Web Apps(OWA)来实现在线编辑word,excel,power point, one note,并集成到自己的网站里去.   1 准备工作 1.1 操作系统 安装了 ...