2019湘潭赛题解 | E题 XTCPC (三种写法)

这道题

在比赛的时候其实已经有思路了

但是在最后45分钟的时候 队友说我们就选一道题来做吧……

然后选了B题 (就是题意理解错误了的那题 so没做出来)

放一下E题题面

 

E - Hello 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 nn show the length of string.(1≤n≤2×1051≤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

赛后 

我们三个人都想补这题

其实比赛的时候已经有思路了 

但是没有很好的实现

将 x t C p c 五个字母出现的位置保存起来

找到 x的位置 < t的位置 < C的位置 < p的位置 < c的位置

计数+1

继续找下一个存在这样关系的位置

以下是三个人的代码

我的:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
char s[200050];
int main()
{
    int n;
    while (~scanf("%d",&n))
    {
        int x=0,t=0,C=0,p=0,c=0;
        scanf("%s",s);
        for (int i=0; i<n; i++)
        {
            if (s[i] == 'x')
                x++;
            else if (s[i]=='t' && x)
            {
                x--;
                t++;
            }
            else if (s[i]=='C' && t)
            {
                t--;
                C++;
            }
            else if (s[i]=='p' && C)
            {
                C--;
                p++;
            }
            else if (s[i]=='c' && p)
            {
                p--;
                c++;
            }
        }
        printf("%d\n",c);
    }
    return 0;
}

起初没有想到这么简洁的思想

在看所有人的代码的时候发现的

瞬间觉得的 怎么这么简单!!

 

Alone写的:

#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
using namespace std;
queue <int> x,t,C,p,c;
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    while(~scanf("%d",&n))
    {
        getchar();
        while(!x.empty())
            x.pop();
        while(!c.empty())
            c.pop();
        while(!t.empty())
            t.pop();
        while(!p.empty())
            p.pop();
        while(!C.empty())
            C.pop();

        char s;
        for(int i=1; i<=n; i++)
        {
            scanf("%c",&s);
            // printf("%c**\n",s);
            if(s=='x')
                x.push(i);
            else if(s=='t')
                t.push(i);
            else if(s=='C')
                C.push(i);
            else if(s=='p')
                p.push(i);
            else if(s=='c')
                c.push(i);
        }

        int ans=0,sign=0;

        while(!x.empty())
        {
            int now1=x.front();
            while(!t.empty())
            {
               // cout << t.front() << " "<< now1<< endl;
                if(t.front()<=now1)
                    t.pop();
                else
                {
                    int now2=t.front();
                    while(!C.empty())
                    {
                        //cout << C.front() << " " << now2 <<endl;
                        if(C.front()<=now2)
                            C.pop();
                        else
                        {
                            int now3=C.front();
                            while(!p.empty())
                            {
                              //  cout << p.front() << " " << now3 << endl;
                                if(p.front()<=now3)
                                    p.pop();
                                else
                                {
                                    int now4=p.front();
                                    while(!c.empty())
                                    {
                                        //cout << c.front() << " "<< now4 <<endl;
                                        if(c.front()<=now4)
                                            c.pop();
                                        else
                                        {
                                            sign=1;
                                            ans+=1;
                                            c.pop();
                                            x.pop();
                                            t.pop();
                                            C.pop();
                                            p.pop();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            break;
                        }
//                        break;
                    }
                    break;
                }
//                break;
            }
            if(sign!=1)
                break;
            if(sign)
            {
                sign=0;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

一看就觉得好吓人

但 我还是把她的代码改好了

(原来的代码是错的 她多写了一个; 还多写了两个break 导致WA了7/8遍 心态都崩了 我就说 你别写了 换个题目做……)

 

大白也WA了三四次…… 

我还没改完 等待ing

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值