1007 CCPC Training Class

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=s1s2s3sn, we use s[l:r] to denote the substring starts from l and ends at r, if l>rs[l:r] is empty. We further define:
Lborderi=max{0j<i | s[1:j]=s[ij+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(T20), 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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YukiRinLL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值