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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋    

            題目地址 :

                  http://acm.hdu.edu.cn/showproblem.php?pid=2689 

            題目描述:

               其實(shí)就是求 冒泡排序時(shí) 的交換次數(shù),  當(dāng)然也可以求逆序數(shù)來解決問題, 下面是2份 代碼:

             

            代碼
            //直接冒泡排序求交換的次數(shù)
            /*

            Mail to   : miyubai@gamil.com
            My Blog   : www.baiyun.me
            Link      : 
            http://www.cnblogs.com/MiYu  || http://m.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   : HDU_2689
            Doc Name  : Sort it
            */
            //#pragma warning( disable:4789 )
            #include <iostream>
            #include 
            <fstream>
            #include 
            <sstream>
            #include 
            <algorithm>
            #include 
            <string>
            #include 
            <set>
            #include 
            <map>
            #include 
            <utility>
            #include 
            <queue>
            #include 
            <stack>
            #include 
            <list>
            #include 
            <vector>
            #include 
            <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            using namespace std;
            int N, num[1010];
            inline 
            void swap ( int &a, int &b ) {
                   a 
            ^= b ^= a ^= b;       
            }
            int bouble () {
                
            int sum = 0;
                
            for ( int i = 0; i < N; ++ i ) {
                     
            for ( int j = 1; j < N - i; ++ j ) {
                          
            if ( num[j-1> num[j] ) {
                               swap ( num[j
            -1], num[j] );
                               
            ++ sum;
                          }    
                     }    
                }    
                
            return sum;
            }
            void print () {
                 
            for ( int i = 0; i < N; ++ i )
                 cout 
            << num[i] << " ";
                 cout 
            << endl;     
            }
            int main ()
            {
                
            while ( scanf ( "%d"&N ) == 1 ) {
                       
            for ( int i = 0; i < N; ++ i ) {
                            scanf ( 
            "%d", num + i );    
                       }       
                       printf ( 
            "%d\n",bouble () );
                      
            // print ();
                }
                
            return 0;
            }

            //樹狀數(shù)組求逆序數(shù)法
            /*

            Mail to   : miyubai@gamil.com
            My Blog   : www.baiyun.me
            Link      : 
            http://www.cnblogs.com/MiYu  || http://m.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   : HDU_2689
            Doc Name  : Sort it
            */
            //#pragma warning( disable:4789 )
            #include <iostream>
            #include 
            <fstream>
            #include 
            <sstream>
            #include 
            <algorithm>
            #include 
            <string>
            #include 
            <set>
            #include 
            <map>
            #include 
            <utility>
            #include 
            <queue>
            #include 
            <stack>
            #include 
            <list>
            #include 
            <vector>
            #include 
            <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            using namespace std;
            int N,val,num[1010],low[1010];
            void init () {
                 
            for ( int i = 0; i <= 1010++ i ) {
                      low[i] 
            = i & ( -i );    
                 }
            }
            void modify ( int x ) {
                 
            while ( x <= N ) {
                        
            ++ num[x];      
                        x 
            += low[x];
                 }     
            }
            int query ( int x ) {
                
            int sum = 0;
                
            while ( x > 0 ) {
                       sum 
            += num[x];
                       x 
            -= low[x];      
                }    
                
            return sum;
            }
            int main ()
            {
                init ();
                
            while ( scanf ( "%d"&N ) == 1 ) {
                       memset ( num, 
            0sizeof ( num ) );  
                       
            int sum = 0;
                       
            for ( int i = 0; i < N; ++ i ) {
                            scanf ( 
            "%d"&val );
                            modify ( val ); 
                            sum 
            += i - query ( val - 1 );   
                       }  
                       printf ( 
            "%d\n", sum );
                }
                 
                
            return 0;
            }

             

            久久精品一区二区三区不卡| 国产成人无码久久久精品一| 日本国产精品久久| 久久精品综合网| 久久99精品国产99久久6男男| 久久99精品免费一区二区| 三级三级久久三级久久| 精品久久一区二区三区| 一级a性色生活片久久无| 亚洲中文字幕无码久久2017| 久久久免费观成人影院| 久久久一本精品99久久精品66| 久久午夜福利电影| 国产91色综合久久免费| 97久久国产综合精品女不卡| 欧美日韩精品久久久免费观看| 国产欧美久久一区二区| 一本一本久久a久久综合精品蜜桃| 国产综合免费精品久久久| 99国产欧美精品久久久蜜芽| 日韩AV无码久久一区二区| 亚洲国产成人精品女人久久久 | 久久久久高潮综合影院| 久久九九有精品国产23百花影院| 久久人人爽人人爽人人片av麻烦| 久久青青草原精品国产软件| 久久天堂电影网| 久久成人精品视频| 99久久精品国产高清一区二区 | 国产精品久久毛片完整版| 日韩人妻无码一区二区三区久久| 亚洲第一永久AV网站久久精品男人的天堂AV | 久久免费小视频| 久久这里只有精品久久| 久久国产精品久久精品国产| 99久久精品日本一区二区免费| 99精品久久精品| 国产精品一区二区久久精品无码| 国产精品99久久不卡| 精品免费久久久久国产一区| 国产免费福利体检区久久|