• <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>
            posts - 12,  comments - 54,  trackbacks - 0
            re: 與臨時對象的斗爭(下) Wang Feng 2009-12-07 11:36
            ans = a+b+c+d+e+f+....;
            如果可以并行的話,這樣很有優勢
            ans = ((a+b)+(c+d))+((e+f)+(g+h));
            你這個+=雖然省去了一些臨時對象,不過也只好一個一個乖乖地+=了,單個cpu的時候沒有事情,多個cpu的時候,大好時間都浪費了。
            void Merge(T a[], int left, int center, int len)

            {

            T *t = new T[len-left];//存放被合并后的元素
            ----------------------------------------------------------------
            C++支持這樣的語法
            T t[len-left];

            我猜想效率會比
            T *t = new T[len-left];

            更高
            re: 自動求導模板庫[未登錄] wang feng 2009-05-02 13:50
            能否返回一個函數指針?
            比如:
            typedef double (fp*) ( const vector<double>&, const double);
            fp f1;
            ........
            fp f2 = d(f1);
            re: C++ 代碼技巧 (續 02)[未登錄] wang feng 2009-04-14 20:30
            class A
            {
            private:
            struct Handle;
            Handle * handle;
            public:
            .........
            };
            這樣的話,連一開始的兩個
            class StreamFilter;
            class EmitModeConfig;
            都不需要了:)
            @guest
            確實是這樣的,要解決的話也不是很困難,只要partation時候把數組random shuffle一下就可以了:)
            @zfv
            偶高中的時候數學競賽全國得過獎的,不太可能沒學好,更不會丟人。
            @doyle
            拜托,我定量計算之前還有一個定性分析,那個是相當好理解的。
            @doyle
            我定量分析中,使用的是一個數學模型;
            我不認為一個有著億萬身家的人,還會像乞丐一樣熱衷于一元錢;
            就是說“如果"酷斃"和"帥呆"的貪婪程度完全精確的一樣呢?”這種可能在我的考慮中幾乎是不存在的。
            @zuhd
            3,5,7,4,0,1
            第一次調用partation(arr, 0, 5)是以1為界分的;
            結果數組被排成
            0 1 7 4 3 5
            返回1
            @zuhd
            如果arr已經給定不可更改,那么這個結果就是唯一的
            我暈倒,有沒有優雅一點的,至少短一點的實現?
            @天策魂之音
            我用隨機數測試過42憶次,沒有出錯過;
            不知道錯誤是什么
            @zuhd
            "程序的運行結果可以有很多種啊"里邊的程序是指 partation還是nth?
            @zuhd
            不是,這段代碼目的是:以A為界,把數組分為兩個部分,前邊部分數值都是不大于A的,后邊的部分的數值都是不小于A的
            @zuhd
            你可以這樣理解:
            1) 找到一個arbitrary value A(這個數值應該是任意的,我圖寫起來利落,直接指定為數組的最后一個元素----比較好的做法是,執行之前,在數組中任意尋找一個元素與數組最后一個元素交換)
            2)一個指針指向數組的第一個元素,往向后掃描,找到第一個大于A的元素,標記為arr[a];
            3)另外一個指針指向數組的最后一個元素,向前掃面,找到第一個小于A的元素arr[b];
            4)交換arr[a] arr[b]
            5)若兩個指針沒有重合,轉到2)
            6)將A與兩個指針重合地點的元素交換
            這樣以來,以A為界,把數組分為兩個部分,前邊部分數值都是不大于A的,后邊的部分的數值都是不小于A的
            re: pku 2253 Frogger Wang Feng 2008-11-06 22:51
            acm中如果涉及到圖的算法,可否直接使用boost graph library?
            @cdy20
            這樣寫的話,用g++編譯后交換失敗;
            用icpc編譯后交換成功,非常奇怪
            可有人給出更多測試?
            我的編譯器:
            $ g++ -v
            Using built-in specs.
            Target: x86_64-unknown-linux-gnu
            Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,treelang --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic
            Thread model: posix
            gcc version 4.3.2 (GCC)
            $ icpc -v
            Version 10.1
            @空明流轉
            @fish_autumn
            請求指點
            copy( arr, arr+size, ostream_iterator<int>( cout, " " ) );
            我覺得這樣寫,看起來容易一點
            因為逗號運算符優先級最低,于是arr+size中的加號在逗號之前;
            我的習慣是先運行的更緊密一些;
            如你比較喜歡的這個
            if (a == b) a = a + b;
            我會寫成
            if (a == b) a = a+b;
            或者
            if (a == b)
            {
            a = a+b;
            }
            或者
            if (a == b)
            ++a;
            或者
            if (a == b)
            {
            ++a;
            }
            re: stl奇怪的copy問題[已解決] Wang Feng 2008-11-06 16:39
            不要當真,當我是純粹灌水就好了:)
            re: stl奇怪的copy問題[已解決] Wang Feng 2008-11-06 15:58
            5 #include <iostream>
            6 #include <string>
            7 #include <vector>
            8 #include <sstream>
            9 #include <utility>
            10 #include <algorithm>
            11 #include <list>
            12 #include <map>
            13 #include <set>
            14 #include <queue>
            15 #include <stack>
            16 #include <bitset>
            17 #include <memory>
            18 #include <cstdio>
            19 #include <cmath>
            20 #include <cstdlib>
            21 #include <cctype>
            22 #include <cstring>
            23 #include <climits>


            還有比這更可怕的么?19個頭文件…………
            敢問.dot文檔如何打開?
            boost中bind這樣來做:
            class button
            {
            public:

            boost::function<void> onClick;
            };

            class player
            {
            public:

            void play();
            void stop();
            };

            button playButton, stopButton;
            player thePlayer;

            void connect()
            {
            playButton.onClick = boost::bind(&player::play, &thePlayer);
            stopButton.onClick = boost::bind(&player::stop, &thePlayer);
            }
            用慣了vim了,對別的編輯器無愛
            re: RamDisk好處! Wang Feng 2008-06-16 18:00
            我這邊是/dev/shm
            re: (C++)一個愚蠢的錯誤 Wang Feng 2008-06-09 18:05
            #include <cstring>
            #include <string>
            re: 5.12汶川大地震(一) Wang Feng 2008-05-13 22:23
            blessing
            貌似我是第一個回帖的,當時看錯的題目,貽笑大方了,今天過來翻翻,居然這么多回應。
            看到面試官說:
            另外告訴其他各位朋友,那個計算7744這個數字的題目,是要用一支筆一張紙嚴禁的推理出來,用來考查人的分析和推理能力的,不然讓人寫代碼實現的。
            于是就推理一番如下:
            -------------------------------------------------------------------------

            題目:
            1000~10000里面的4位平方數你給我找出來,數字的規則是 abcd, a=b c=d

            推理:
            1. 依照題意,這個數字可以寫為
            x = 1100a + 11b = s * s ( 0 < a, b < 10 )
            由于1000<= x = s * s <= 10000,故
            31 < s <= 100
            2. 由于 100a + b = s * s / 11
            故s必定能夠被11整除,記
            s = 11c ( 2 < c < 10 )
            于是得到
            11*c * c = 100a + b = y
            很顯然y必定為11的倍數
            3. 由于一個數,如果能夠被11整除,那么它的奇位數之和與偶位數之和之差必定能為11所整除(貌似是初中學過的一個定理,很容易推導,我猜想這個才是整個推理過程的要點)
            很顯然y的“奇位數之和與偶位數之和之差”
            sub = a + b 必須能夠被11整除
            由于限制條件 ( 0 < a, b < 10 )的存在
            a+b =11 必定成立
            4. 將它代入到
            11*c * c = 100a + b
            得到
            9a = c*c - 1
            于是 a = (c-1)(c+1) / (3*3)
            5. 很顯然要讓c-1跟c+1同時都可被3整除是不可能的,所以c+1 c-1這兩個數字中,必定有一個能夠被9整除,另一個是質數
            由于 2 < c < 10
            故c = 8
            因此s = 88
            6. x = 88 * 88
            @zellux
            是我看錯了題意,不好意思
            1000~10000里面的4位平方數你給我找出來,數字的規則是 abcd, a=b c=d
            --------------------------------------------------------------------------
            可能你記錯了范圍了,這個范圍里邊不存在
            int
            strcmp(const char *s1, const char *s2)
            {
            while (*s1 == *s2)
            {
            if (*s1 == 0)
            return 0;
            ++s1;
            ++s2;
            }
            return *(unsigned const char *)s1 - *(unsigned const char *)(s2);
            }
            re: TopPlayer播放器源碼發布 Wang Feng 2008-05-04 14:45
            對了,編譯器
            $ gcc -v
            Using built-in specs.
            Target: i686-pc-linux-gnu
            Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,treelang --enable-threads=posix --mandir=/usr/share/man --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic
            Thread model: posix
            gcc version 4.3.0 (GCC)
            re: TopPlayer播放器源碼發布 Wang Feng 2008-05-04 14:44
            第一個文件就編譯不過去
            部分輸出:
            CLV_ListView.c:2831: error: ‘CIs_ListViewData’ has no member named ‘m_pColumns’
            CLV_ListView.c:2834: error: ‘rInvalid’ undeclared (first use in this function)
            CLV_ListView.c:2835: error: ‘CIs_ListViewData’ has no member named ‘m_rClient’
            CLV_ListView.c:2837: error: ‘CIs_ListViewData’ has no member named ‘m_pColumns’
            CLV_ListView.c:2838: error: ‘CIs_ListViewData’ has no member named ‘m_hWnd’
            CLV_ListView.c:2838: error: ‘FALSE’ undeclared (first use in this function)
            CLV_ListView.c: In function ‘CLV_Invalidate’:
            CLV_ListView.c:2849: error: ‘CIs_ListViewData’ has no member named ‘m_hWnd’
            CLV_ListView.c:2849: error: ‘FALSE’ undeclared (first use in this function)
            CLV_ListView.c: In function ‘RemoveSelectedItem’:
            CLV_ListView.c:2859: error: ‘BOOL’ undeclared (first use in this function)
            CLV_ListView.c:2859: error: expected ‘;’ before ‘bMoved’
            CLV_ListView.c:2864: error: ‘struct <anonymous>’ has no member named ‘m_hPlaylistViewControl’
            CLV_ListView.c:2865: error: ‘struct <anonymous>’ has no member named ‘m_hPlaylistViewControl’
            CLV_ListView.c:2868: error: ‘BROWSEINFO’ undeclared (first use in this function)
            CLV_ListView.c:2868: error: expected ‘;’ before ‘browseinfo’
            CLV_ListView.c:2869: error: ‘LPITEMIDLIST’ undeclared (first use in this function)
            CLV_ListView.c:2869: error: expected ‘;’ before ‘itemlist’
            CLV_ListView.c:2873: error: ‘browseinfo’ undeclared (first use in this function)
            CLV_ListView.c:2873: error: ‘HWND’ undeclared (first use in this function)
            CLV_ListView.c:2873: error: expected ‘;’ before ‘G_MTabCtrl’
            CLV_ListView.c:2877: error: ‘BIF_EDITBOX’ undeclared (first use in this function)
            CLV_ListView.c:2882: error: ‘itemlist’ undeclared (first use in this function)
            CLV_ListView.c:2882: warning: implicit declaration of function ‘SHBrowseForFolder’
            CLV_ListView.c:2885: warning: implicit declaration of function ‘SHGetPathFromIDList’
            CLV_ListView.c:2885: error: ‘struct <anonymous>’ has no member named ‘main_text_last_browsed_dir’
            CLV_ListView.c:2871: warning: unused variable ‘directorychoice’
            CLV_ListView.c:2890: error: ‘struct <anonymous>’ has no member named ‘m_hPlaylistViewControl’
            CLV_ListView.c:2893: warning: implicit declaration of function ‘lstrcpyn’
            CLV_ListView.c:2901: warning: implicit declaration of function ‘lstrcpy’
            CLV_ListView.c:2901: error: ‘struct <anonymous>’ has no member named ‘main_text_last_browsed_dir’
            CLV_ListView.c:2902: warning: implicit declaration of function ‘lstrcat’
            CLV_ListView.c:2903: error: ‘bMoved’ undeclared (first use in this function)
            CLV_ListView.c:2903: warning: implicit declaration of function ‘MoveFile’
            CLV_ListView.c:2906: warning: implicit declaration of function ‘CPLI_SetPath’
            CLV_ListView.c:2912: error: ‘struct <anonymous>’ has no member named ‘m_hPlaylistViewControl’
            CLV_ListView.c:2914: error: ‘struct <anonymous>’ has no member named ‘m_hPlaylistViewControl’
            CLV_ListView.c:2858: warning: unused variable ‘cNewPath’
            CLV_ListView.c:2857: warning: unused variable ‘cPath’
            CLV_ListView.c: At top level:
            CLV_ListView.c:2916: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘CPlaylistWindow_CB_onAppMessage’
            CLV_ListView.c:2958: error: expected ‘)’ before ‘hWnd’
            CLV_ListView.c:3018: error: expected ‘)’ before ‘hWnd’
            make: *** [CLV_ListView.o] Error 1
            re: 模板參數名命名慣例 Wang Feng 2008-04-21 22:12
            說起宏定義,其實在文件前面定義,用完了之后在文件最后取消是個很好的習慣
            比如

            #define PI 3.1415926535897932384626433
            .....

            #undef PI
            unix上怎么辦?

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(4)

            隨筆分類

            隨筆檔案

            Link List

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久久久中文字幕人妻最新 | 久久99国产精品久久99| 99精品久久精品一区二区| 久久er热视频在这里精品| 久久久久亚洲AV无码专区桃色| 日韩亚洲国产综合久久久| 国产美女久久精品香蕉69| 久久国产三级无码一区二区| 久久人人爽人人人人爽AV| 欧美久久精品一级c片片| 久久精品一区二区三区AV| 国内精品久久久久影院网站| 三上悠亚久久精品| 久久精品国产第一区二区| 久久棈精品久久久久久噜噜| 日韩电影久久久被窝网| 亚洲精品无码久久千人斩| 久久久久久国产精品美女 | 久久99精品久久久久久hb无码| 久久无码国产| 91精品国产色综久久| 日韩av无码久久精品免费| 女人高潮久久久叫人喷水| 久久久精品无码专区不卡| 久久婷婷久久一区二区三区| 久久久久久久女国产乱让韩| 久久久黄片| 亚洲精品乱码久久久久久不卡| 婷婷综合久久狠狠色99h| 久久久久亚洲精品无码蜜桃| 亚洲欧美日韩久久精品第一区| 婷婷久久综合九色综合绿巨人| 国产呻吟久久久久久久92| 热99re久久国超精品首页| 久久国产精品99精品国产| 国产成人久久精品一区二区三区| 伊人久久精品影院| 国产成人久久精品一区二区三区| 欧美亚洲国产精品久久高清| 精品国产99久久久久久麻豆| 亚洲乱码中文字幕久久孕妇黑人|