codeforces#505--A Doggo Recoloring
A. Doggo Recoloring
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.
The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.
Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color xxsuch that there are currently at least two puppies of color xx and recolor all puppies of the color xx into some arbitrary color yy. Luckily, this operation can be applied multiple times (including zero).
For example, if the number of puppies is 77 and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose xx='c' right now, because currently only one puppy has the color 'c'.
Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.
Input
The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of puppies.
The second line contains a string ss of length nn consisting of lowercase Latin letters, where the ii-th symbol denotes the ii-th puppy's color.
Output
If it's possible to recolor all puppies into one color, print "Yes".
Otherwise print "No".
Output the answer without quotation signs.
Examples
input
Copy
6
aabddc
output
Copy
Yes
input
Copy
3
abc
output
Copy
No
input
Copy
3
jjj
output
Copy
Yes
Note
In the first example Slava can perform the following steps:
- take all puppies of color 'a' (a total of two) and recolor them into 'b';
- take all puppies of color 'd' (a total of two) and recolor them into 'c';
- take all puppies of color 'b' (three puppies for now) and recolor them into 'c'.
In the second example it's impossible to recolor any of the puppies.
In the third example all the puppies' colors are the same; thus there's no need to recolor anything.
只要有一个字母出现了两次就可以了
注意要特判n=1的时候
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define inf 0x3f3f3f3f
using namespace std;
int n;
const int maxn = 1e5 + 5;
int puppy[30];
char s[maxn];
int main()
{
while(scanf("%d", &n) != EOF){
cin>>s;
memset(puppy, 0, sizeof(puppy));
bool flag = false;
for(int i = 0; i < strlen(s); i++){
puppy[s[i] - 'a']++;
if(puppy[s[i] - 'a'] >= 2){
flag = true;
break;
}
}
if(flag || n == 1){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return 0;
}
codeforces#505--A Doggo Recoloring的更多相关文章
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring
[链接] 我是链接,点我呀:) [题意] 你可以把出现次数大于1的颜色换成其他颜色. 问你最后能不能全都变成同一种颜色 [题解] 判断一下有没有出现次数大于1的就好. 有的话.显然可以一直用它变颜色. ...
- Codeforces 505 A Mr. Kitayuta's Gift【暴力】
题意:给出一个字符串,可以向该字符串的任意位置插入一个字母使其变成回文串 因为字符串的长度小于10,枚举插入的字母,和要插入的位置,再判断是否已经满足回文串 #include<iostream& ...
- Codeforces #505(div1+div2) D Recovering BST
题意:给你一个升序的数组,元素之间如果gcd不为1可以建边,让你判断是否可以建成一颗二叉搜索树. 解法:dp,首先建图,然后进行状态转移.因为如果点k左端与i相连,右端与k相连,则i和k可以相连,同时 ...
- Codeforces #505(div1+div2) C Plasticine zebra
题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长? 思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 ...
- Codeforces #505(div1+div2) B Weakened Common Divisor
题意:给你若干个数对,每个数对中可以选择一个个元素,问是否存在一种选择,使得这些数的GCD大于1? 思路:可以把每个数对的元素乘起来,然后求gcd,这样可以直接把所有元素中可能的GCD求出来,从小到大 ...
- 【CF1025A】Doggo Recoloring(签到)
题意:给定一个长度为 n 的小写字母串.可以将出现次数大于等于2的字母全部变成另一个小写字母,问最后能否将该小写字母串的所有字母变成同一个字母 n<=1e5 思路: #include<cs ...
- Codeforces Round #505
Codeforces Round #505 A. Doggo Recoloring 题目描述:给定一个字符串,每次选择一个在字符串里面出现至少两次的字符,然后将这种字符变成那一种指定的字符,问最终这个 ...
- Codeforces Round #505 (Div 1 + Div 2) (A~D)
目录 Codeforces 1025 A.Doggo Recoloring B.Weakened Common Divisor C.Plasticine zebra D.Recovering BST( ...
- Codeforces Round #505 (Div 1 + Div 2 Combined) Solution
从这里开始 题目列表 瞎扯 Problem A Doggo Recoloring Problem B Weakened Common Divisor Problem C Plasticine zebr ...
随机推荐
- ubuntu 12.04 LTS server 中文乱码【转】
ubuntu 12.04 LTS server 中文乱码 最近装了一台ubuntu 12.04 server装完后是没有桌面的,后来又手动安装了桌面,但进行后发现桌面是乱码,应该是缺少字体在googl ...
- CommonJS初识
CommonJS是什么 CommonJS是一个标准库,或者说是一组规范.因为官方并没有给出真正的代码实现,而是给出一些代码组织规范.常用模块的api.包(Package)的命名规范和具体格式. Com ...
- thinkphp 解析带html标签的内容
1.实例一 <?php echo htmlspecialchars_decode($goodsinfo['Specification']);?> 2.实例二 {$show.article| ...
- SQLServer跨服务器访问数据库(openrowset/opendatasource/openquery)
SQLServer跨服务器访问数据库(openrowset/opendatasource/openquery) 1.启用Ad Hoc Distributed Queries 在使用openrowset ...
- 笔记本怎么设置WIfi热点
随着手机的发展,流量的消耗也是大大地增加.虽然很多手机支持wifi,但是不加密或者知道密码的wifi热点却寥寥无几.笔记本的无线网卡显出神通了.那么,如何在笔记本上建立wifi热点呢? 工具/原料 一 ...
- FairyGUI学习
官网:http://www.fairygui.com/ 教程:http://www.taikr.com/course/446/tasks 博客:http://gad.qq.com/article/de ...
- AOPR密码过滤器
在Advanced Office Password Recovery任一攻击的破解选项设置窗口都有一个“编辑密码过滤器”按钮,设置好AOPR密码破解工具的密码过滤器可以大大提高破解速度,下文将具体介绍 ...
- Android开发之程序猿必需要懂得Android的重要设计理念2(5.20更新版)
上篇文章介绍了Android开发的设计理念的一部分,并没有得到博友们的多大认可,仅仅看到了一位博友在以下留言期待下一篇文章的发表,为了这小小的唯一支持.我决定继续把后面的8个要点介绍一下,自己也潜心反 ...
- 查看进程动态:top
top命令用于查看进程动态,即进程使用系统资源的情况,常见用法如下: [root@localhost ~]$ top # 动态查看进程使用资源的情况,每三秒刷新一次 [root@localhost ~ ...
- Linux ulimit 命令
ulimit命令用来限制系统用户对 shell 资源的访问,常见用法如下: [root@localhost ~]$ ulimit -a # 查看当前所有的资源限制 [root@localhost ~] ...