http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1007&cid=909

CCPC Training Class

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 5145    Accepted Submission(s): 2911

Problem Description
Baby volcano is helping his CCPC coach preparing a new CCPC training contest. He wants to generate high quality data on border tree(There is no need to know what border tree is), but he encounters some troubles. Could you please help him?

In this paragraph we formally define the data quality problem. For some string s=s1s2s3⋯sn, we use s[l:r] to denote the substring starts from l and ends at r, if l>r, s[l:r] is empty. We further define:

Lborderi=max{0≤j<i | s[1:j]=s[i−j+1:i]}

to denote the longest border at some position i, then we define D(i) to denote the length of border chain at position i:

D(i)={0D(LBorderi)+1i=0i>0

The quality W of this string is define as the maximum of D:

W=maxi=0nD(i)

To distinguish border tree with naive brute force algorithms, baby volcano need to generate strings such that its quality W is as large as possible.

Now given a string s, you could permute s arbitrarily. What is the maximum quality W you could reach after permuting s?

 

Input

In the first line there is a number T(T≤20), denotes the number of test cases.
In the next T lines, for each line there is a string s(1≤|s|≤105), denotes the input string, all inputs are formed in lowercases.
 

Output

Output T lines, for each line, you need to output ''Case #t: m''(without quotes), where t is the index of this test case, m is the maximum quality you could reach after permuting.
 

Sample Input

5
abcde
sankaranarayanan
abbccaabc
programming
monotone
 
Sample Output
Case #1: 1
Case #2: 7
Case #3: 3
Case #4: 2
Case #5: 3
 
思路:输出出现次数最多的字母的出现次数
代码:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std; int T;
string str;
vector<int> ans; int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
for (int i = 1; i <= T; ++i)
{
ans.resize(26, 0);
cin >> str;
for (int j = 0; j < str.length(); ++j)
{
ans[str[j] - 'a']++;
}
sort(ans.begin(), ans.end());
cout << "Case #" << i << ": " << ans[25] << '\n';
ans.clear();
}
return 0;
}

  

 
 

1007 CCPC Training Class的更多相关文章

  1. 2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛总结

    1003 Express Mail Taking 题意:有n个柜子(编号1-n),m封信,k号位置有钥匙,现在需要取信封,并且每取一次信封都要从k号位置进行领取一次钥匙,再去有信封的位置领取信封,问最 ...

  2. hdu 4941 2014 Multi-University Training Contest 7 1007

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  3. hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  4. HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)

    6356.Glad You Came 题意就是给你一个随机生成函数,然后从随机函数里确定查询的左右区间以及要更新的val值.然后最后求一下异或和就可以了. 线段树,区间最大值和最小值维护一下,因为数据 ...

  5. HDU 6315.Naive Operations-线段树(两棵树合并)(区间单点更新、区间最值、区间求和)+思维 (2018 Multi-University Training Contest 2 1007)

    6315.Naive Operations 题意很好理解,但是因为区间求和求的是向下取整的a[i]/b[i],所以直接分数更新区间是不对的,所以反过来直接当a[i]==b[i]的时候,线段树对应的位置 ...

  6. 【2018 Multi-University Training Contest 2 1007】Naive Operations

    [链接] 我是链接,点我呀:) [题意] 给你两个数组a,b; b数组是1..n的一个排列. 现在给你两种操作: add l,r将a[l..r]都加上1 query l,r 询问$∑^r_l\frac ...

  7. hdoj6708 2019 CCPC网络选拔赛 1007 Windows Of CCPC

    #include <cstdio> #include <iostream> #include <algorithm> using namespace std; ch ...

  8. 2016 Multi-University Training Contest 10

    solved 7/11 2016 Multi-University Training Contest 10 题解链接 分类讨论 1001 Median(BH) 题意: 有长度为n排好序的序列,给两段子 ...

  9. HDU 4638 Group (2013多校4 1007 离线处理+树状数组)

    Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  10. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

随机推荐

  1. C#线程池核心技术:从原理到高效调优的实用指南

    1. 引言 在现代软件开发中,多线程编程是提升应用程序性能的关键手段.随着多核处理器的普及,合理利用并发能力已成为开发者的重要课题.然而,线程的创建和销毁是一个昂贵的过程,涉及系统资源的分配与回收,频 ...

  2. AI图像生成的"套娃"生意:一个月入240万美元的AI工具站

    AI图像生成的"套娃"生意:一个月入240万美元的AI工具站 今天和大家分享一个让我既佩服又警醒的案例--flux1.ai. 这个项目用最简单粗暴的方式,在AI图像生成这个红海市场 ...

  3. Filezilla提权漏洞复现

    FileZilla是一个免费开源的FTP软件,分为客户端版本和服务器版本,具备所有的FTP软件功能.可控性.有条理的界面和管理多站点的简化方式使得Filezilla客户端版成为一个方便高效的FTP客户 ...

  4. F-47(copy 邓大顾)

    *&---------------------------------------------------------------------* *& F-47过账 *&--- ...

  5. Apache Hudi 在袋鼠云数据湖平台的设计与实践

    在大数据处理中,实时数据分析是一个重要的需求.随着数据量的不断增长,对于实时分析的挑战也在不断加大,传统的批处理方式已经不能满足实时数据处理的需求,需要一种更加高效的技术来解决这个问题.Apache ...

  6. ChunJun 顺利晋级“2022 年中国开源创新大赛”决赛,并荣获“优秀开源项目/社区”奖项

    日前,"2022年中国开源创新大赛"初赛晋级名单公布,易用.稳定.高效的批流统一的数据集成框架 ChunJun顺利晋级决赛,并荣获"2022年中国开源创新大赛优秀开源项目 ...

  7. Axios 简单使用

    axios({ method: "post", headers: { "Content-Type": "application/json" ...

  8. C# 23种设计模式汇总(更新完毕) john大叔

    https://www.cnblogs.com/johntom/archive/2012/04/06/2435273.html C# 23种设计模式  创建型模式工厂方法(Factory Method ...

  9. 新能源制造升级核心引擎:五大MES厂商如何破局行业痛点?

    在全球"双碳"目标驱动下,中国新能源产业迎来爆发式增长,动力电池.光伏组件.储能设备产能持续扩张.然而,高速发展的背后,工艺变更频繁导致生产计划失效.多系统数据孤岛阻碍全流程追溯. ...

  10. MySQL 10 MySQL为什么有时候会选错索引?

    场景引入 我们知道,MySQL中一张表可以支持多个索引.但是写SQL语句时,并没有主动指定使用哪个索引,而是由MySQL来确定.而有时候,MySQL会选错索引,导致执行速度变得很慢. 举个例子,假设一 ...