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 ...
随机推荐
- am335x backlight
/****************************************************************************** * am335x backlight * ...
- PHP 初学
虚拟目录和虚拟主机的关系?虚拟主机可以设置多个,虚拟目录呢? 以为phpstorm和Intellij一样,结果不是!它直接将所有内容上传(部署)到服务器即可,不像Intellij那样还调用服务器?? ...
- vector 排序
#include <vector> #include <algorithm> 一.vector保存的是基础数据类型(int.char.float等) vector<int ...
- const 与#define 的比较
const 与#define 的比较 C++ 语言可以用 const 来定义常量,也可以用 #define 来定义常量.但是前者比后 者有更多的优点: (1) const 常量有数据类型,而宏常量没有 ...
- 在C语言中实现面向对象(2)
C语言是结构化和模块化的语言,它是面向过程的.但它也可以模拟C++实现面向对象的功能.那么什么是对象呢?对象就是一个包含数据以及于这些数据有关的操作的集合,也就是包含数据成员和操作代码(即成员函数). ...
- MJRefresh原理分析
MJRefresh是流行的下拉刷新控件.前段时间为了修复一个BUG.读了它的源代码.本文总结一下实现的原理 下拉刷新的基本原理 大部分的下拉刷新控件.都是用contentInset实现的.默认情况下. ...
- 使用libcurl源代码编译只是的问题
curl 7.21.6 + vs2005 就把curl的.c文件加到project中编译.报错信息非常古怪: setup_once.h(274) : error C2628: '<unnamed ...
- PHP截断函数mb_substr()
提示:mb_substr在于php中是默认不被支持的我们需要在在windows目录下找到php.ini打开编辑,搜索mbstring.dll,找到;extension=php_mbstring.dll ...
- 关于直播学习笔记-005-nginx-rtmp-win32在Win10上使用
在Win10上使用nginx-rtmp-win32会提示文件路径问题. 可以将nginx-rtmp-win32拷贝到用户目录文件夹之中. 在命令行中执行nginx.exe程序
- 动易CMS漏洞收集
动易SiteWeaver6.8短消息0day跨站漏洞 user用户登陆,默认账号密码 admin/admin888 短消息代码模式下编辑,预览 <img src="../Skin/bl ...