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

            Life is Good.

            Enhance Tech and English
            隨筆 - 65, 文章 - 20, 評論 - 21, 引用 - 0
            數據加載中……

            10億個浮點數,求出其中最大的10000個.


            #include 
            "stdafx.h"
            #include 
            <vector>
            #include 
            <iostream>
            #include 
            <algorithm>
            #include 
            <functional> // for greater<>
            using namespace std;

            int _tmain(int argc, _TCHAR* argv[])
            {
              vector
            <float> bigs(10000,0);
              vector
            <float>::iterator it;

              
            // Init vector data
              for (it = bigs.begin(); it != bigs.end(); it++)
              {
                
            *it = (float)rand()/7// random values;
              }

              cout 
            << bigs.size() << endl;

              make_heap(bigs.begin(),bigs.end(), greater
            <float>()); // The first one is the smallest one!

              
            float ff;
              
            for (int i = 0; i < 1000000000; i++)
              {
                ff 
            = (float) rand() / 7;
                
            if (ff > bigs.front()) // replace the first one ?
                {
                  
            // set the smallest one to the end!
                  pop_heap(bigs.begin(), bigs.end(), greater<float>()); 

                  
            // remove the last/smallest one
                  bigs.pop_back(); 

                  
            // add to the last one
                  bigs.push_back(ff); 

                  
            // mask heap again, the first one is still the smallest one
                  push_heap(bigs.begin(),bigs.end(),greater<float>());
                }
              }

              
            // sort by ascent
              sort_heap(bigs.begin(), bigs.end(), greater<float>()); 

              
            // sort by descent
              
            //sort_heap(bigs.begin(), bigs.end()); 
              
            //sort_heap(bigs.begin(), bigs.end(), less<float>()); 

              
            return 0;
            }

            posted on 2011-06-02 16:51 Mike Song 閱讀(840) 評論(0)  編輯 收藏 引用 所屬分類: C/C++面試題目

            久久人人爽人人爽人人AV东京热 | 伊人丁香狠狠色综合久久| 精品久久久久久久无码| 久久精品青青草原伊人| 国产麻豆精品久久一二三| 久久这里只有精品首页| 久久夜色精品国产亚洲| 亚洲乱码精品久久久久.. | 亚洲国产日韩欧美久久| 狠狠久久亚洲欧美专区 | 久久香蕉超碰97国产精品| 久久香综合精品久久伊人| 中文精品99久久国产 | 国产精品免费看久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 久久久精品国产sm调教网站| 久久久久综合国产欧美一区二区| 久久妇女高潮几次MBA| 久久久久亚洲AV成人网| 久久综合九色综合久99| 久久无码人妻一区二区三区| 日本免费一区二区久久人人澡 | 国产偷久久久精品专区| 日本免费一区二区久久人人澡| 久久亚洲AV成人无码电影| 久久人人爽人人爽人人片AV不| 久久777国产线看观看精品| 久久伊人五月丁香狠狠色| 亚洲七七久久精品中文国产 | 久久综合视频网站| 国产成人精品综合久久久| 国产精品激情综合久久| 久久毛片免费看一区二区三区| 久久夜色精品国产亚洲| 久久精品国产日本波多野结衣| 久久久久久久波多野结衣高潮| 99精品国产免费久久久久久下载| 热99RE久久精品这里都是精品免费| 精品久久久久久无码人妻蜜桃| 久久精品国产一区二区| 亚洲αv久久久噜噜噜噜噜|