• <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串被打碎成兩半,現在給出這些打碎了之后的串,要求求出原串。
            首先,原串的長度一定是打碎了之后的串中最長的長度加上最短的長度。設打碎之后的串中最長串組成集合S,最短串組成集合T,那么原串肯定為ST或TS中的某種。由于S、T中元素個數必定小于等于2,所以可能的結果最多只有8種。枚舉這8種結果,然后檢測是否符合要求即可。
            檢測的時候,對于某個長度為L的串,要快速檢索到長度為(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;
            }
            posted on 2011-05-20 15:44 lee1r 閱讀(1060) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數據結構題目分類:排序
            久久99九九国产免费看小说| 久久久精品人妻一区二区三区蜜桃| 久久亚洲AV成人无码软件| 久久久久无码国产精品不卡| 午夜福利91久久福利| 99久久婷婷国产综合亚洲| 国产精品青草久久久久福利99| 久久久黄色大片| 久久精品18| 亚洲国产欧洲综合997久久| 精品久久久久久久久久中文字幕| 亚洲乱码中文字幕久久孕妇黑人 | 热久久国产精品| 久久99久久99精品免视看动漫| 精品欧美一区二区三区久久久 | 久久96国产精品久久久| 人妻少妇久久中文字幕一区二区| 久久涩综合| 久久综合成人网| 精品久久久久久久久中文字幕| 色偷偷91久久综合噜噜噜噜| 久久久久久毛片免费播放| 国内精品伊人久久久久影院对白| 久久亚洲AV成人无码电影| 99精品国产免费久久久久久下载| 99久久国产亚洲高清观看2024| 国产精品美女久久久免费| 午夜精品久久久久久毛片| 一级女性全黄久久生活片免费 | 久久只有这精品99| 99久久人人爽亚洲精品美女| 午夜天堂av天堂久久久| 久久精品一区二区三区中文字幕| 人妻精品久久无码专区精东影业| 久久天天躁狠狠躁夜夜2020| 色综合久久88色综合天天| 国产精品一区二区久久| 99久久免费国产特黄| 狠狠色丁香婷婷综合久久来来去| 久久人爽人人爽人人片AV | 久久精品极品盛宴观看|