• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            題目大意:一些相同的01串被打碎成兩半,現(xiàn)在給出這些打碎了之后的串,要求求出原串。
            首先,原串的長(zhǎng)度一定是打碎了之后的串中最長(zhǎng)的長(zhǎng)度加上最短的長(zhǎng)度。設(shè)打碎之后的串中最長(zhǎng)串組成集合S,最短串組成集合T,那么原串肯定為ST或TS中的某種。由于S、T中元素個(gè)數(shù)必定小于等于2,所以可能的結(jié)果最多只有8種。枚舉這8種結(jié)果,然后檢測(cè)是否符合要求即可。
            檢測(cè)的時(shí)候,對(duì)于某個(gè)長(zhǎng)度為L(zhǎng)的串,要快速檢索到長(zhǎng)度為(maxlength+minlength-L)的串,使用multimap<int,string>可以很方便地做到。
            以下是我的代碼:
            #include<iostream>
            #include
            <vector>
            #include
            <string>
            #include
            <map>
            #include
            <algorithm>
            #include
            <cstdio>
            using namespace std;

            bool cmp(const string &a,const string &b)
            {
                
            return (a.size()<b.size() ||(a.size()==b.size() && a<b));
            }

            int main()
            {
                #ifndef ONLINE_JUDGE
                freopen(
            "data.in","r",stdin);
                freopen(
            "data.out","w",stdout);
                
            #endif

                
            int T;
                cin
            >>T;
                cin.
            get();
                cin.
            get();
                
            bool first(true);
                
            while(T--)
                {
                    
            int minl(0x7f7f7f7f),maxl(0);
                    vector
            <string> a;
                    
            string t;
                    
            while(getline(cin,t) && !t.empty())
                    {
                        a.push_back(t);
                        minl
            =min(minl,(int)(t.size()));
                        maxl
            =max(maxl,(int)(t.size()));
                    }

                    sort(a.begin(),a.end(),cmp);
                    a.erase(unique(a.begin(),a.end()),a.end());

                    multimap
            <int,string> r;
                    
            for(int i=0;i<a.size();i++)
                        r.insert(make_pair(a[i].size(),a[i]));

                    
            string ans;
                    multimap
            <int,string>::iterator
                        ibegin
            =r.begin(),
                        iend
            =r.upper_bound(minl),
                        jend
            =r.end(),
                        jbegin
            =r.lower_bound(maxl);
                    
            for(multimap<int,string>::iterator i=ibegin;i!=iend;i++)
                        
            for(multimap<int,string>::iterator j=jbegin;j!=jend;j++)
                        {
                            
            string now(i->second+j->second);
                            
            bool success(true);
                            
            for(multimap<int,string>::iterator k=r.begin();k!=r.end();k++)
                            {
                                multimap
            <int,string>::iterator
                                    pbegin
            =r.lower_bound(minl+maxl-k->first),
                                    pend
            =r.upper_bound(minl+maxl-k->first);
                                
            bool can(false);
                                
            for(multimap<int,string>::iterator l=pbegin;l!=pend;l++)
                                {
                                    
            if(k->second+l->second==now || l->second+k->second==now)
                                        can
            =true;
                                }
                                
            if(!can)
                                {
                                    success
            =false;
                                    
            break;
                                }
                            }
                            
            if(success)
                                ans
            =now;

                            now
            =j->second+i->second;
                            success
            =true;
                            
            for(multimap<int,string>::iterator k=r.begin();k!=r.end();k++)
                            {
                                multimap
            <int,string>::iterator
                                    pbegin
            =r.lower_bound(minl+maxl-k->first),
                                    pend
            =r.upper_bound(minl+maxl-k->first);
                                
            bool can(false);
                                
            for(multimap<int,string>::iterator l=pbegin;l!=pend;l++)
                                {
                                    
            if(k->second+l->second==now || l->second+k->second==now)
                                        can
            =true;
                                }
                                
            if(!can)
                                {
                                    success
            =false;
                                    
            break;
                                }
                            }
                            
            if(success)
                                ans
            =now;
                        }

                    
            if(first)
                        first
            =false;
                    
            else
                        cout
            <<endl;
                    cout
            <<ans<<endl;
                }

                
            return 0;
            }
            女同久久| 国内精品伊人久久久久影院对白| 亚洲国产精品久久久天堂| 伊人热人久久中文字幕| 狠狠色狠狠色综合久久| 亚洲国产成人久久一区WWW| 国产精品久久波多野结衣| 婷婷久久香蕉五月综合加勒比| 97久久久精品综合88久久| 久久综合日本熟妇| av国内精品久久久久影院| 国内精品久久久人妻中文字幕| 国产精品内射久久久久欢欢| 国产午夜精品理论片久久| 久久久久久久女国产乱让韩| 久久无码AV中文出轨人妻| 欧美日韩精品久久久免费观看| 国产精品久久久天天影视| 久久综合亚洲鲁鲁五月天| 色综合久久中文色婷婷| 国产69精品久久久久9999| 久久亚洲私人国产精品| 国产99精品久久| 人妻少妇久久中文字幕一区二区| 久久久无码精品亚洲日韩软件| 久久亚洲国产午夜精品理论片 | 国产精品亚洲综合专区片高清久久久 | 久久夜色精品国产www| 粉嫩小泬无遮挡久久久久久| 亚洲中文字幕无码久久精品1 | 久久精品一本到99热免费| 欧美激情精品久久久久久| 青青草原综合久久大伊人精品| 久久精品国产网红主播| 亚洲成人精品久久| 精品久久久久久中文字幕| 狠狠色综合久久久久尤物| 国产成人香蕉久久久久| 久久99热这里只有精品国产 | 久久久久国产精品人妻| 欧美精品乱码99久久蜜桃|