• <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 閱讀(833) 評論(0)  編輯 收藏 引用 所屬分類: C/C++面試題目

            精品多毛少妇人妻AV免费久久| 性做久久久久久久久久久| 精品久久久无码人妻中文字幕| 精品多毛少妇人妻AV免费久久| 人妻精品久久久久中文字幕69 | 午夜福利91久久福利| 久久综合久久美利坚合众国| 一本色道久久88精品综合| 99久久99久久精品国产片| 久久午夜无码鲁丝片秋霞| 久久婷婷国产麻豆91天堂| 久久久这里有精品| 久久777国产线看观看精品| 久久久午夜精品福利内容| 99久久精品无码一区二区毛片| 综合久久给合久久狠狠狠97色 | 久久国产乱子伦免费精品| 一级做a爰片久久毛片人呢| 中文字幕无码精品亚洲资源网久久| 久久精品国产久精国产| 伊人色综合久久天天人手人婷| 久久精品国产99久久香蕉| 丰满少妇人妻久久久久久| 国产精品久久久久久久久久影院| 亚洲一区中文字幕久久| 久久亚洲精品人成综合网| 思思久久精品在热线热| 思思久久99热免费精品6| 国产伊人久久| 亚洲精品高清久久| 成人a毛片久久免费播放| 亚洲天堂久久精品| 一本久久久久久久| 91精品国产综合久久香蕉 | 久久精品国产亚洲77777| 亚洲国产另类久久久精品| 奇米影视7777久久精品人人爽| 亚洲性久久久影院| 性欧美丰满熟妇XXXX性久久久 | 国产精品一区二区久久| 99久久无码一区人妻a黑|