UESTC486(2011四川省省赛)

Good Morning

Edit

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

Sam loves Lily very much that he shows his love to her through all kinds of ways. This morning, Lily received an e-mail from Sam. Lily knows that Sam hided "good morning" in this mail. Lily tried several ways to resort the letters (including the space ' ') so that more "good morning"s could be found. The number of "good morning" appeared in a specified string equals the number of positions from which Lily could see a consecutive string "good morning".

With so many letters, Lily is about to be dizzy. She asks you to tell her what is the maximum number of "good morning"s appear in this mail after rearranged in some way.

Input

First an integer T T (T≤20 T≤20), indicates there are T T test cases.

Every test case begins with a single line consist of only lowercase letters and space which is at most 1000 1000 characters.

Output

k

Sample input and output

Sample InputSample Output
2
gninrom doog
ggoooodd  mmoorrnniinngg
Case #1: 1
Case #2: 2


这道题特别有意思, 把给出的字符串任意排序,问里面最多可以出现多少次good morning。

按照一般的想法, 统计里面出现了多少次字母和空格;然后把每次每个字母出现的次数除以一个单词中这个字符出现的次数;

然后最小的就是解。

但是仔细理解下题意, 是最多能出现多少次,不是用里面的字符能组成多少个good morning。

所以第一个组成的good moring的morning 的g可以作为下一下good morning 的good的g。

这就比较坑了。

#include<bits/stdc++.h>
using namespace std;

#define EPS 1e-7
#define clr(x) memset(x, 0, sizeof(x))
#define ll long long
#define PI acos(-1.0)

const int INF = 1e9;
const int MOD=1000000007;
const int MAXN = 1e6;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};


int mp[MAXN];
char s[MAXN];
int main()
{
    int t;
    cin>>t;
    getchar();
    for(int cas=1;cas<=t;cas++)
    {
        memset(s,0,sizeof(s));
        gets(s);
        memset(mp,0,sizeof(mp));
        printf("Case #%d: ",cas);
        for(int i=0;i<strlen(s);i++)
        {
            mp[s[i]]++;
        }
        int maxc=INF;
        //cout<<mp[' ']<<endl;
        if(mp['g'] > 0)
            mp['g']--;
        maxc=min(maxc,mp['o']/3);
        maxc=min(maxc,mp['n']/2);
        maxc=min(maxc,mp['g']);
        maxc=min(maxc,mp['d']);
        maxc=min(maxc,mp['m']);
        maxc=min(maxc,mp['i']);
        maxc=min(maxc,mp['r']);
        maxc=min(maxc,mp[' ']);
        cout<<maxc<<endl;
    }


}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值