• <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)在給出這些打碎了之后的串,要求求出原串。
            首先,原串的長度一定是打碎了之后的串中最長的長度加上最短的長度。設打碎之后的串中最長串組成集合S,最短串組成集合T,那么原串肯定為ST或TS中的某種。由于S、T中元素個數(shù)必定小于等于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 閱讀(1052) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:數(shù)據(jù)結構題目分類:排序
            久久99精品国产麻豆不卡| 日本道色综合久久影院| 香蕉久久夜色精品国产尤物| 亚洲精品无码久久毛片| 久久乐国产综合亚洲精品| 久久成人国产精品| 国产精品激情综合久久| 久久99热这里只频精品6| 色欲久久久天天天综合网精品| 精品永久久福利一区二区| 久久精品国产亚洲精品| 99久久99久久久精品齐齐| 久久综合狠狠综合久久97色| 久久综合给合久久狠狠狠97色| 91精品国产91久久| 久久丫精品国产亚洲av不卡 | 国产成人精品综合久久久| 精品国产VA久久久久久久冰| 久久播电影网| 国产精品久久网| 精品久久久久久久无码| 久久AV无码精品人妻糸列| 久久久久综合国产欧美一区二区 | 久久九九兔免费精品6| 久久99久久99小草精品免视看 | 日本久久中文字幕| 亚洲国产精品人久久| 成人国内精品久久久久一区| 中文字幕久久波多野结衣av| 性做久久久久久久久浪潮| 久久国产精品偷99| 99久久亚洲综合精品网站| 国产亚洲欧美成人久久片| 国产一级持黄大片99久久| 久久久精品国产sm调教网站 | 久久一区二区三区免费| 久久久亚洲精品蜜桃臀| 久久精品免费网站网| 久久精品中文字幕一区| 中文字幕无码久久人妻| 亚洲精品视频久久久|