[CodeForces]-672B-Different is Good

[CodeForces]-672B-Different is Good
原题:
B - Different is Good
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit

Status

Practice

CodeForces 672B
Appoint description:
Description
A wise man told Kerem “Different is good” once, so Kerem wants all things in his life to be different.

Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string “aba” has substrings “” (empty substring), “a”, “b”, “a”, “ab”, “ba”, “aba”.

If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.

Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.

Input
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.

The second line contains the string s of length n consisting of only lowercase English letters.

Output
If it’s impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.

Sample Input
Input
2
aa
Output
1
Input
4
koko
Output
2
Input
5
murat
Output
0
Hint
In the first sample one of the possible solutions is to change the first character to ‘b’.

In the second sample, one may change the first character to ‘a’ and second character to ‘b’, so the string becomes “abko”.

题目大意:就是给定一个字符串,问经过最少多少次修改可以使该字符串的所有子串都不相同。

题目分析:因为是所有子串都不相同,所以只要有相同的2个字母的时候一阶子串就会相同。所以只要使所有的字母都不相同就可以了。

个人陷阱:发现遍历字符串将对应的字母放入对应的数组位置的时候:

for (int i = 0;i<n;i++){
         vis[str[i]-'a']++; 
 }

这里的n指的是str.length(),如果我取i<=n时就会在DEVC++中莫名蹦掉,只是小于就没有事,奇怪。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std  ;

int vis[28]; //存字母的重复个数

int main()
{
    int len ; 
    cin>>len ; 
    string str ; 
    cin>>str;
    int ans = 0 ;
    int n = str.length();
    if(len > 26 ){
        cout<<"-1";
    }
    else if(len>0&&len<=26){
        for (int i = 0;i<n;i++){
         vis[str[i]-'a']++; 
        }
        for(int j = 0 ; j < 26 ;j ++){
            if(vis[j]>1){
                ans += vis[j]-1 ;
            }
        }
        cout<<ans;
    }
    else if(len = 0 ){
        cout<<"0";
    }

     //cout<<vis[0]<<endl; 
    return 0 ; 
}
# 高校智慧校园解决方案摘要 智慧校园解决方案是针对高校信息化建设的核心工程,旨在通过物联网技术实现数字化校园的智能化升级。该方案通过融合计算机技术、网络通信技术、数据库技术和IC卡识别技术,初步实现了校园一卡通系统,进而通过人脸识别技术实现了更精准的校园安全管理、生活管理、教务管理和资源管理。 方案包括多个管理系统:智慧校园管理平台、一卡通卡务管理系统、一卡通人脸库管理平台、智能人脸识别消费管理系统、疫情防控管理系统、人脸识别无感识别管理系统、会议签到管理系统、人脸识别通道管理系统和图书馆对接管理系统。这些系统共同构成了智慧校园的信息化基础,通过统一数据库和操作平台,实现了数据共享和信息一致性。 智能人脸识别消费管理系统通过人脸识别终端,在无需接触的情况下快速完成消费支付过程,提升了校园服务效率。疫情防控管理系统利用热成像测温技术、视频智能分析等手段,实现了对校园人员体温监测和疫情信息实时上报,提高了校园公共卫生事件的预防和控制能力。 会议签到管理系统和人脸识别通道管理系统均基于人脸识别技术,实现了会议的快速签到和图书馆等场所的高效通行管理。与图书馆对接管理系统实现了一卡通系统与图书馆管理系统的无缝集成,提升了图书借阅的便捷性。 总体而言,该智慧校园解决方案通过集成的信息化管理系统,提升了校园管理的智能化水平,优化了校园生活体验,增强了校园安全,并提高了教学和科研的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值