HDU6536 Hello xtCpc 2019CCPC湖南全国邀请赛(广东省赛、江苏省赛)重现赛

 

题意:给你一个字符串,让你在里面寻找可不连续的字符串“xtCpc”,问有多少个

          题目有问题,给了个gdCpc   

          样例:输入:10 xtCxtCpcpc     输出:2

思路:只要保证每个字符前面出现的次数大于本字符出现的次数就好(想想为什么)

           为了保证字符顺序

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
char s[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        scanf("%s",s);
        int x1=0,x2=0,x3=0,x4=0,x5=0,ans=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='x') x1++;
            if(s[i]=='t'&&x2<x1) x2++;
            if(s[i]=='C'&&x3<x2) x3++;
            if(s[i]=='p'&&x4<x3) x4++;
            if(s[i]=='c'&&x5<x4) x5++;
            if(x1&&x2&&x3&&x4&&x5)
            {
                ans++;
                x1--;
                x2--;
                x3--;
                x4--;
                x5--;
            }
        }  
        printf("%d\n",ans);
    }
    return 0;
}

Hello GDCPC

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1321    Accepted Submission(s): 163


 

Problem Description

You have a string of lowercase letters.You need to find as many sequence “gdCpc” as possible.But letters in the same position can only be used once。

 

 

Input

The input file contains two lines.

The first line is an integer n show the length of string.(1≤n≤2×105)

The second line is a string of length n consisting of lowercase letters and uppercase letters.

 

 

Output

The input file contains an integer show the maximum number of different subsequences found.

 

 

Sample Input

 

10

gdCgdCpcpc

 

 

Sample Output

2

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值