TB 16 10 29 PM

来源:互联网 发布:sublime text 3调试js 编辑:程序博客网 时间:2024/05/29 09:20

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;}