TB 16 10 29 PM

T1

80分 最后两个点变态,没有初始序列,然后就不知道怎么输入了。。
前面点不算难,只不过原始序列中有三个同色球在一起的,比较坑,然后就算是模拟了,
string里面有一些奇怪的函数,非常有用。。

str.erase(pos,n); 删除从pos开始的n个字符
str.insert(pos,s); 插入

注意在消掉三个球之后看一下是否还可以继续消除

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string c;
string a;
int n;
int main()
{
    cin>>a;
    scanf("%d",&n);
    bool flag=0;
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k>>c;
        a.insert(k,c);
        int tot=1;
        do
        {
            flag=0;
            tot=1;

            int h=k-1,t=k+1,now=k;
            while(a[h]==a[now]&&h>=0)
            {
                tot++;
                h--;
            }
            h++;
            while(a[t]==a[now]&&t<a.size())
            {
                tot++;
                t++;
            }
            t--;
            if(tot>=3)
            {
                a.erase(h,tot);
                flag=1;
            }
            k=h;
        }while(flag==1);
        if(a.size()==0)
            cout<<"-"<<endl;
        else cout<<a<<endl;
    }
    return 0;
}

T2

做过,记忆犹新
先找到最大的,然后前面的入栈,然后看剩下的最大的在前面还是后面,在前面就不管(在前一个就出栈),在后面的话重复操作,直到栈为空

#include<cstdio>
using namespace std;
int n,a[1100000],dis[1100000],pos[1100000],stc[1100000],posm=-1,max1=-1;
int main()
{

    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(int i=n;i>=1;i--)
    {
        if(a[i]>max1)
        {
            posm=i;
            max1=a[i];
        }
        dis[i]=max1;
        pos[i]=posm;
    }
    int tail=1;
    int top=1;

       while(tail<=n)
        {
            if(dis[tail]>stc[top])
            while(tail<=pos[tail]-1)  
            {
                top++;
                stc[top]=a[tail];
                tail++;
            }
            printf("%d ",a[tail]);

            tail=pos[tail]+1;
            while(dis[tail]<stc[top])
            {
                printf("%d ",stc[top]);
                top--;
            }

        }
    return 0;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值