zoukankan      html  css  js  c++  java
  • Codeforces Round #527 (Div. 3)C(多重集,STRING)

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e6+7;
    pair<string,int>p[maxn];
    int nn,n;
    int cmp(pair<string,int>a,pair<string,int>b){
        return a.first.length()<b.first.length();
    }
    char ans[maxn];
    multiset<string>sst;
    int judge(string pre,string suf){
        string s=pre+suf[suf.length()-1];//将最长的加上同样长的另一个字符可以拼接成完整串(或是完整串的镜像)
        multiset<string>st;
        for(int i=0;i<n-1;i++){
            st.insert(s.substr(0,i+1));//0-i+1
            st.insert(s.substr(i+1));//i+1-end
        }//将所有前缀后缀全被扔进多重集st中
        if(st!=sst)//镜像
            return 0;
        for(int i=1;i<=nn;i+=2){
            string ss=s.substr(0,p[i].first.length());//截取长度开始比较,string的优势在于可以直接等于比较
            string sss=s.substr(n-p[i].first.length());
            if(p[i].first==ss && p[i+1].first==sss){
                ans[p[i].second]='P';
                ans[p[i+1].second]='S';
            }
            else{
                ans[p[i+1].second]='P';
                ans[p[i].second]='S';
            }
        }
        return 1;
    }
    int main(){
        scanf("%d",&n);
        nn=2*n-2;
        for(int i=1;i<=nn;i++){
            cin>>p[i].first;
            p[i].second=i;
            sst.insert(p[i].first);
        }
        sort(p+1,p+1+nn,cmp);
        if(judge(p[nn].first,p[nn-1].first)){
            for(int i=1;i<=nn;i++){
                printf("%c",ans[i]);
            }
        }
        else if(judge(p[nn-1].first,p[nn].first)){
            for(int i=1;i<=nn;i++){
                printf("%c",ans[i]);
            }
        }
        return 0;
    }
     
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    Codeforces 834D The Bakery
    hdu 1394 Minimum Inversion Number
    Codeforces 837E Vasya's Function
    Codeforces 837D Round Subset
    Codeforces 825E Minimal Labels
    Codeforces 437D The Child and Zoo
    Codeforces 822D My pretty girl Noora
    Codeforces 799D Field expansion
    Codeforces 438D The Child and Sequence
    Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D)
  • 原文地址:https://www.cnblogs.com/ldudxy/p/10155363.html
Copyright © 2011-2022 走看看