【CodeForces 672B】Different is Good
字符串所有子串要不同。求修改最少多少个字符。
因为只能是26个字母,显然大于26的不可能有答案,其它情况ans+=u[i]-1;u[i]是字母出现的次数。
#include<cstdio>
char s;
int n,u[],ans;
int main(){
scanf("%d ",&n);
for(int i=;i<n;i++){
scanf("%c ",&s);
u[s-'a']++;
}
if(n>)printf("-1");
else{
for(int i=;i<;i++)
if(u[i])ans+=u[i]-;
printf("%d",ans);
}
}
【CodeForces 672B】Different is Good的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- IntelliJ IDEA 编译maven项目以及运行测试前编译项目
Maven编译及命令行输出 右侧Maven Projects, 打开, 选取某个Project打开至Lifecycle/package 或其他任何一个lifecycle选项, 在上面右键Run Mav ...
- xpath 参考
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Te ...
- Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- Session一次错误记录
/// <summary> /// 验证登录状态是否已失效 /// </summary> /// <returns>< ...
- 使用perl实现scp批量分发
perl模块Net::SCP::Expect批量下发文件 用Net::SSH::Perl和Net::SCP::Expect写部署脚本 scp分发文件的perl脚本 Perl SCP操作 #!/usr/ ...
- python中from module import * 的一个陷阱
from module import *把module中的成员全部导到了当前的global namespace,访问起来就比较方便了.当然,python style一般不建议这么做,因为可能引起nam ...
- Bootstrap系列 -- 8. 代码显示
一. Bootstrap中的代码块 代码块一般在博客中使用的较多,比较博客园中提供的贴代码. 在Bootstrap中提供了三种形式的代码显示 1. 使用<code></code> ...
- 【JavaEE企业应用学习记录】验证配置
package sanglp; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.validat ...
- 聚类算法kmeans
1. 聚类问题 所谓聚类问题,就是给定一个元素集合D,其中每个元素具有n个可观察属性,使用某种算法将D划分成k个子集,要求每个子集内部的元素之间相异度尽可能低,而不同子集的元素相异度尽可能高. 2. ...
- eclipse中的常用插件
常用插件整理: http://blog.sina.com.cn/s/blog_60b5e13e0102vz6q.html 插件带有链接 http://blog.csdn.net/kagoy/ar ...