2019湘潭赛后补题 E题 XTCPC

2019湘潭赛后补题 E题 XTCPC
You have a string of lowercase letters.You need to find as many sequence “xtCpc” 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
xtCxtCpcpc
Sample Output
2

题意分析:在一段字符串中找到 可断固定顺序 的“xtCpc”的个数,这里有一个坑点是要多组输入。

解题思路:如果前一个字母出现的次数要多于后面的字母,那么这个字母可以作为答案中字母,当完成一个子串后删去他们;

解题思考:这道题是不可以排序的,因为我们要找 xtCpc,所以,对于字符串的子串,如果我们可以找到符合的子串,那么这个符合的子串是不会影响后面的字母排列顺序,如果这个字母在它前面字母的后面出现就可以被接受(xtCpc中,只要t在x的后面出现就可以被利用),也就是目前它前面的字母出现的比这个字母多,那么这个字母就可以利用。

#include<iostream>   //Hello XTcPc
#include<cstring>
using namespace std;
char a[200005];
int main(){
	int x,t,c,C,p,ans,n;
	while(~scanf("%d",&n)){
		x=p=t=c=C=p=0;
		scanf("%s",a);
		int m=strlen(a);
		ans=0;
		for(int i=0;i<m;i++){
			if(a[i]=='x'){
				x++;
			}
			if(a[i]=='t'&&x>t){
				t++;
			}
			if(a[i]=='C'&&t>C){
				C++;
			}
			if(a[i]=='p'&&C>p){
				p++;
			}
			if(a[i]=='c'&&p>c){
				c++;
			}
		}
		while(x&&t&&C&&p&&c){
				x--;
				t--;
				C--;
				p--;
				c--;
				ans++;
			}
			printf("%d\n",ans);
	}
}

  • 13
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值