ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

E - Hello XTCPC from: SDUT 2021 Summer Individual Contest - 1(for 20)

2021-07-27 09:59:38  阅读:164  来源: 互联网

标签:Summer include 20 Contest int 字母 ++ now ct


Description
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

Output

2

Hint
题目大意:找到最多的xtCpc,单词里面字母的相对位置不能变,每个字母最多用一次。题目里没说但这次是多组输入(很淦!)。

这题有很多解法,我还是暴力(虽然尝试几次暴力都超时了2333,换了个思路继续暴力)

C++

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N = 2e5+7;
int n;
char s[N];
int a[6][N];//标记指定字母(第一维度 1x 2t...)出现的位置(依次存到第二维度)
int ct[6];//存入时,某字母存到第几个了,最终会变为某字母总个数
int now[6];//判断时,某字母读到第几个了

int main()
{
    while(scanf("%d%s",&n,s)!=EOF){
        mem(a,0);
        mem(ct,0);
        mem(now,0);
        int cnt = 0;
        for(int i=0;i<n;i++){
        	//读到某字母就储存到a数组里
            if(s[i] == 'x')
                a[1][ct[1]++]=i;
            else if(s[i] == 't')
                a[2][ct[2]++]=i;
            else if(s[i] == 'C')
                a[3][ct[3]++]=i;
            else if(s[i] == 'p')
                a[4][ct[4]++]=i;
            else if(s[i] == 'c')
                a[5][ct[5]++]=i;
        }
        int l = min(min(min(min(ct[1],ct[2]),ct[3]),ct[4]),ct[5]);
        //cout<<"l:"<<l<<endl;
        while(l--){///保证最小次数
            int flag = 1;///是否满足一次xtCpc条件
            for(int i=1;i<5;i++){///每次对比前后位置(四次)
                while(a[i][now[i]] >= a[i+1][now[i+1]]) {///直到后面字母的位次比前面字母的位次大,保证相对位置不变
                    //cout << "while!" << endl;
                    now[i+1] ++;///否则后面向后找一个位置
                    if(now[i+1] >= ct[i+1]){///如果向后找的时候到达边界
                        flag = 0;///不满足一次条件,并且退出
                        break;
                    }
                }
                now[i] ++;//1 2 3 4 字母完成一次读入
            }
            now[5]++;//5 字母完成一次读入
            if(flag){
                cnt ++;
            }
        }
        cout << cnt <<endl;
    }
    return 0;
}

别卷了家人们,孩子只会写水题

标签:Summer,include,20,Contest,int,字母,++,now,ct
来源: https://blog.csdn.net/Kirie_/article/details/119133800

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有