• <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>

            The Fourth Dimension Space

            枯葉北風(fēng)寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢(mèng)令

            Codeforces Beta Round #24 B題

                  此題如果一下子想到了思路確實(shí)是應(yīng)該很快出的,這題暴露了我基本功不扎實(shí)的弱點(diǎn),對(duì)qsort中cmp函數(shù)和sort中cmp函數(shù)的使用沒有完全弄明白,通過這題終于搞明白了啊,初學(xué)者如果只是按網(wǎng)上的寫法套個(gè)模板還是遠(yuǎn)遠(yuǎn)不夠的,因?yàn)榻鉀Q的問題是在不斷變化的,一定要深入研究其原理,才能遇神殺神,遇佛殺佛。
                  既然提到了這題,我說下兩個(gè)函數(shù)的不同之處吧,我覺得肯定有很多人不會(huì),我記得很多人還跟我說這兩個(gè)函數(shù)的寫法是一樣的。。。。。至于qsort的cmp函數(shù)中要用const void * 這些我就不說了,直接切入主題,對(duì)qsort的cmp函數(shù),返回值是int,這個(gè)函數(shù)要考慮<,=,>三種情況,而sort的cmp函數(shù),返回值是bool ,也就是只有兩種情況,如果你用過sort進(jìn)行結(jié)構(gòu)體排序的話,你會(huì)發(fā)現(xiàn)其實(shí)你只要重載小于符號(hào)就可以進(jìn)行排序,其實(shí)這個(gè)cmp函數(shù)就等價(jià)于你重載了結(jié)構(gòu)體的<運(yùn)算符,明白了么?

            Sort版:
                  
            #include <iostream> 
            #include 
            <string>
            #include 
            <vector> 
            #include 
            <algorithm> 
            #include 
            <map> 

            using namespace std; 

            map 
            <string,int> mm;
            map 
            <int,string> mm2;

            int points[10= 251815 , 12 , 10 , 86 , 421 }

            struct node

                
            int a[1010]; 
                
            int p; 
                
            int pos;
            }


            node per[
            2000]; 
            int ca,n; 
            string s; 


            int id=0;
            bool cmp1(node a, node b) 

                
            if (a.p != b.p) 
                    
            return a.p > b.p; 
                
            for (int i = 0; i < id; i ++
                    
            if (a.a[i] != b.a[i]) 
                        
            return a.a[i] > b.a[i]; 
                
            return false;
            }


            bool cmp2(node a, node b) 

                
            if (a.a[0!= b.a[0]) 
                    
            return a.a[0> b.a[0]; 
                
            if (a.p != b.p) 
                    
            return a.p > b.p; 
                
            for (int i = 1; i < id; i ++
                    
            if (a.a[i] != b.a[i]) 
                        
            return a.a[i] > b.a[i];
                
            return false;
            }
             


            int main() 

                cin 
            >> ca; 
                mm.clear();
                mm2.clear();
                
            while(ca--)
                

                    cin 
            >> n; 
                    
            for (int i = 0; i < n; i ++
                    

                        cin 
            >> s; 
                        
            if (mm.find(s) == mm.end()) 
                        

                            mm[s] 
            = id; 
                            mm2[id]
            =s;
                            per[id].pos
            =id;
                            per[id].p 
            = 0
                            id
            ++;
                        }
             
                        per[mm[s]].a[i]
            ++
                        
            if (i < 10
                            per[mm[s]].p 
            += points[i]; 
                    }
             
                }
             
                sort(per, per 
            + id, cmp1); 
                cout 
            << mm2[per[0].pos]<< endl; 
                sort(per, per 
            + id, cmp2); 
                cout 
            << mm2[per[0].pos] << endl; 
                
            return 0
            }





            Qsort版



            #include
            <iostream>
            #include
            <algorithm>
            #include
            <string>
            #include
            <map>
            using namespace std;

            int point[10]={25,18,15,12,10,8,6,4,2,1};//前10名得到的分?jǐn)?shù)
            map<string,int>mm;
            map
            <int,string>mm2;

            struct node
            {
                
            int p;
                
            int a[2000];
                
            int pos;
            }
            per[2000];

            int id=0;
            int getid(string s)
            {
                
            if(mm.find(s)==mm.end())
                
            {
                    mm[s]
            =id++;
                    mm2[id
            -1]=s;
                    
            return id-1;
                }

                
            else
                    
            return mm[s];
            }




            /*
            bool cmp1(node a, node b) 

                if (a.p != b.p) 
                    return a.p > b.p; 
                int i;
                for (i = 0; i < 100; i ++) 
                    if (a.a[i] != b.a[i]) 
                        return a.a[i] > b.a[i]; 
                return false;

            }

            bool cmp2(node a,node b)
            {
                if(a.a[0]!=b.a[0])
                    return a.a[0]>b.a[0];
                if(a.p!=b.p)
                    return a.p>b.p;
                int i;
                for(i=0;i<id;i++)
                    if(a.a[i]!=b.a[i])
                        return a.a[i]>b.a[i];
                return false;
            }
            */





            int cmp1(const void *a,const void *b)
            {
                node 
            *c=(node*)a;
                node 
            *d=(node*)b;
                
                
            if(c->p!=d->p)
                
            {

                    
            if(c->> d->p)
                        
            return -1;
                    
            else 
                        
            return 1;
                }

                
            int i;
                
            for(i=0;i<id;i++)
                
            {

                    
            if(c->a[i]>d->a[i])
                        
            return -1;
                    
            else if(c->a[i] < d->a[i])
                        
            return 1;
                }

                
            return 0;
            }



            int cmp2(const void *a,const void *b)
            {
                node 
            *c=(node*)a;
                node 
            *d=(node*)b;


                
            if(c->a[0]>d->a[0])
                        
            return -1;
                
            else if(c->a[0< d->a[0])
                        
            return 1;


                
            if(c->p!=d->p)
                
            {

                    
            if(c->> d->p)
                        
            return -1;
                    
            else 
                        
            return 1;
                }

                
            int i;
                
            for(i=1;i<id;i++)
                
            {

                    
            if(c->a[i]>d->a[i])
                        
            return -1;
                    
            else if(c->a[i] < d->a[i])
                        
            return 1;
                }

                
            return 0;
            }






            int main()
            {

                
            int ca;
                scanf(
            "%d",&ca);
                mm.clear();
                mm2.clear();
                
            while(ca--)
                
            {
                    
            int n;
                    scanf(
            "%d",&n);
                    
            //cin.ignore();
                    string s;
                    
            int i;
                    
            for(i=0;i<n;i++)
                    
            {
                        cin
            >>s;
                        
            int k=getid(s);
                        
            if(i<10)
                        
            {
                            per[k].p
            +=point[i];    
                        }

                        per[k].a[i]
            ++;
                        per[k].pos
            =k;
                    }

                }

                qsort(per,id,
            sizeof(per[0]),cmp1);
                cout
            <<mm2[per[0].pos]<<endl;
                qsort(per,id,
            sizeof(per[0]),cmp2);
                cout
            <<mm2[per[0].pos]<<endl;


                
            return 0;
            }


            基本功基本功^_^

            posted on 2010-07-29 11:41 abilitytao 閱讀(1404) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久精品国产影库免费看 | AAA级久久久精品无码片| 免费一级欧美大片久久网| 精品国产91久久久久久久a| 欧美国产成人久久精品| 一本久久知道综合久久| 国产精品久久久久久吹潮| 久久免费大片| 久久久久亚洲av无码专区| 无码国内精品久久综合88| 亚洲精品午夜国产VA久久成人| 亚洲AV无码久久精品成人| 久久精品免费网站网| 欧美午夜精品久久久久免费视| 国产精品热久久无码av| 无码日韩人妻精品久久蜜桃| 久久成人国产精品一区二区| 无码国内精品久久人妻蜜桃| 精品久久久久久国产免费了| 亚洲精品午夜国产VA久久成人| 四虎影视久久久免费| 狠狠色丁香久久综合婷婷| 97久久国产综合精品女不卡 | 漂亮人妻被中出中文字幕久久| 国内精品久久久久久久久电影网| 久久国产精品99久久久久久老狼 | 99久久久精品免费观看国产| 久久久久人妻一区精品果冻| 久久99精品综合国产首页| av色综合久久天堂av色综合在| 欧美午夜精品久久久久久浪潮| 99久久精品免费| 91亚洲国产成人久久精品网址| 91精品国产乱码久久久久久| 狠狠色综合网站久久久久久久高清 | 亚洲日韩欧美一区久久久久我 | 久久久久久噜噜精品免费直播| 久久九九亚洲精品| 麻豆精品久久精品色综合| 国产欧美久久久精品| 国产精品久久国产精品99盘|