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

            Dain

            寫出一個可以工作的程序并不夠

            統計

            留言簿(3)

            積分與排名

            良師益友

            閱讀排行榜

            評論排行榜

            置頂隨筆 #

            [置頂]勵志

            師兄太強了,拿到了baidu、M$、Google的offer,可是實驗室第一人啊,實在是admire
            現在都說工作難找,不過只要努力,總會找到自己滿意的,向師兄學習
            我一定要努力啊

            posted @ 2006-12-08 10:42 Dain 閱讀(864) | 評論 (14)編輯 收藏

            2008年9月18日 #

            tate

            posted @ 2008-09-18 19:58 Dain 閱讀(182) | 評論 (0)編輯 收藏

            2007年5月29日 #

            Getting the Minimum and Maximum Values for a Numeric Type

            Getting numeric limits

            #include <iostream>
            #include 
            <limits>

            using namespace std;

            template
            <typename T>
            void showMinMax() {
               cout 
            << "min: " << numeric_limits<T>::min() << endl;
               cout 
            << "max: " << numeric_limits<T>::max() << endl;
               cout 
            << endl;
            }


            int main() {
               cout 
            << "short:" << endl;
               showMinMax
            <short>();
               cout 
            << "int:" << endl;
               showMinMax
            <int>();
               cout 
            << "long:" << endl;
               showMinMax
            <long>();
               cout 
            << "long long:" << endl;
               showMinMax
            <long long>();
               cout 
            << "float:" << endl;
               showMinMax
            <float>();
               cout 
            << "double:" << endl;
               showMinMax
            <double>();
               cout 
            << "long double:" << endl;
               showMinMax
            <long double>();
               cout 
            << "unsigned short:" << endl;
               showMinMax
            <unsigned short>();
               cout 
            << "unsigned int:" << endl;
               showMinMax
            <unsigned int>();
               cout 
            << "unsigned long:" << endl;
               showMinMax
            <unsigned long>();
               cout 
            << "unsigned long long:" << endl;
               showMinMax
            <unsigned long long>();
            }

            posted @ 2007-05-29 10:38 Dain 閱讀(822) | 評論 (2)編輯 收藏

            2007年5月25日 #

            3017

            #include <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <vector>

            using namespace std;

            struct Node 
            {
                
            int i,j;
                
            int value;
            }
            ;

            long num[100000];
            vector
            <Node> matrix;

            int main() {
                
            long n;
                
            long long m;
                scanf(
            "%ld %lld",&n,&m);

                
            long i,j;
                
            for(i = 0;i < n;++i) {
                    scanf(
            "%ld",&num[i]);
                }


                
            for(i = 0;i < n;++i) {
                    
            if(num[i] > m) {
                        
            break;
                    }

                }


                
            if(i < n) {
                    printf(
            "-1\n");

                    
            return 0;
                }


                
            long long res = -1;
                
            long long sum;
                
            long max,min = 0;
                
            for(i = 0;i < n;++i) {
                    
            if(i > 0{
                        min 
            = 1000000;
                        
            for(j = 0;j < matrix.size();++j) {
                            
            if(matrix[j].j == i - 1 && matrix[j].value < min) {
                                min 
            = matrix[j].value;
                            }

                        }

                    }

                    
            else {
                        min 
            = 0;
                    }


                    sum 
            = 0;
                    Node node;
                    max 
            = -1;
                    
            for(j = i;j < n;++j) {
                        sum 
            += num[j];
                        
            if(sum <= m) {
                            
            if(max < num[j]) {                    
                                max 
            = num[j];
                            }

                            node.i 
            = i;
                            node.j 
            = j;
                            node.value 
            = max + min;
                            matrix.push_back(node);
                            
            if(j == n - 1{
                                
            if(res != -1{
                                    
            if(node.value < res) {
                                        res 
            = node.value;
                                    }

                                }

                                
            else {
                                    res 
            = node.value;
                                }

                            }

                        }

                        
            else {
                            
            break;
                        }

                    }

                }

                
                printf(
            "%lld\n",res);

                
            return 0;
            }

            posted @ 2007-05-25 10:06 Dain 閱讀(270) | 評論 (0)編輯 收藏

            3017

            #include <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <vector>

            using namespace std;

            struct Node 
            {
                
            int i,j;
                
            int value;
            }
            ;

            long num[100000];
            vector
            <Node> matrix;

            int main() {
                
            long n;
                
            long long m;
                scanf(
            "%ld %lld",&n,&m);

                
            long i,j;
                
            for(i = 0;i < n;++i) {
                    scanf(
            "%ld",&num[i]);
                }


                
            for(i = 0;i < n;++i) {
                    
            if(num[i] > m) {
                        
            break;
                    }

                }


                
            if(i < n) {
                    printf(
            "-1\n");

                    
            return 0;
                }


                
            long long res = -1;
                
            long long sum;
                
            long max,min = 0;
                
            for(i = 0;i < n;++i) {
                    
            if(i > 0{
                        min 
            = 1000000;
                        
            for(j = 0;j < matrix.size();++j) {
                            
            if(matrix[j].j == i - 1 && matrix[j].value < min) {
                                min 
            = matrix[j].value;
                            }

                        }

                    }

                    
            else {
                        min 
            = 0;
                    }


                    sum 
            = 0;
                    Node node;
                    max 
            = -1;
                    
            for(j = i;j < n;++j) {
                        sum 
            += num[j];
                        
            if(sum <= m) {
                            
            if(max < num[j]) {                    
                                max 
            = num[j];
                            }

                            node.i 
            = i;
                            node.j 
            = j;
                            node.value 
            = max + min;
                            matrix.push_back(node);
                            
            if(j == n - 1{
                                
            if(res != -1{
                                    
            if(node.value < res) {
                                        res 
            = node.value;
                                    }

                                }

                                
            else {
                                    res 
            = node.value;
                                }

                            }

                        }

                        
            else {
                            
            break;
                        }

                    }

                }

                
                printf(
            "%lld\n",res);

                
            return 0;
            }

            posted @ 2007-05-25 10:06 Dain 閱讀(226) | 評論 (0)編輯 收藏

            2007年5月24日 #

            不要再犯低級的錯誤

            最近,總是犯非常低級的錯誤
            看題不仔細
            將j誤寫成k,而且怪的是,測試的例子都通過了,后來通過debug才找到了這個很低級的錯誤

            真是氣人啊

            不要再犯了

            posted @ 2007-05-24 13:56 Dain 閱讀(255) | 評論 (0)編輯 收藏

            2007年4月16日 #

            列出所有9位數,它的前n位能被n整除

            最簡單的是窮舉,不過那可要O(9*109),不可取 

            #include <iostream>
            #include 
            <vector>
            #include 
            <algorithm>

            using namespace std;

            vector
            <int> fun(int n)
            {
                vector
            <int> last,all;
                
            int i,j,k;
                
            for(i = 1;i < 10;++i)
                    all.push_back(i);

                
            if(n == 1)
                    
            return all;

                
            int size;
                
            int num;
                
            for(i = 2;i <= n;++i)
                
            {
                    last 
            = all;
                    all.clear();
                    size 
            = (int)last.size();
                    
            for(j = 0;j < size;++j)
                    
            {
                        
            for(k = 0;k < 10;++k)
                        
            {
                            num 
            = last[j] * 10 + k;
                            
            if(num % i == 0)
                                all.push_back(num);
                        }

                    }

                    last.clear();
                }


                
            return all;
            }

            posted @ 2007-04-16 17:29 Dain 閱讀(1117) | 評論 (5)編輯 收藏

            2007年2月7日 #

            最大的子序列和問題

            求解該問題的四種算法:
            時間O(N3),算法一
            int ?MaxSubsequenceSum( const ? int ?A[], int ?N)
            {
            ????
            int
            ?ThisSum,MaxSum,i,j,k;
            ????
            ????MaxSum?
            = ? 0
            ;
            ????
            for (i? = ? 0 ;i? < ?N;i ++
            )
            ????????
            for (j? = ?i;j? < ?N;j ++
            )
            ????????
            {
            ????????????ThisSum?
            = ? 0
            ;
            ????????????
            for (k? = ?i;k? <= ?j;k ++ )????ThisSum? +=
            ?A[k];????????????????
            ????????????
            if (ThisSum? > ?MaxSum)????MaxSum? =
            ?ThisSum;
            ????????}

            ????????
            ????
            return ?MaxSum;
            }
            時間O(N2),算法二
            int ?MaxSubsequenceSum( const ? int ?A[], int ?N)
            {
            ????
            int
            ?ThisSum,MaxSum,i,j;
            ????
            ????MaxSum?
            = ? 0
            ;
            ????
            for (i? = ? 0 ;i? < ?N;i ++
            )
            ????
            {
            ????????ThisSum?
            = ? 0
            ;
            ????????
            for (j? = ?i;j? < ?N;j ++
            )
            ????????
            {
            ????????????ThisSum?
            +=
            ?A[k];????????????????
            ????????????
            if (ThisSum? > ?MaxSum)????MaxSum? =
            ?ThisSum;
            ????????}

            ????}

            ????????
            ????
            return ?MaxSum;
            }
            時間O(NlogN),算法三
            static ? int ?MaxSubSum( const ? int ?A[], int ?Left, int ?Right)
            {
            ????
            int
            ?MaxLeftSum,MaxRightSum;
            ????
            int
            ?MaxLeftBorderSum,MaxRightBorderSum;
            ????
            int
            ?LeftBorderSum,RightBorderSum;
            ????
            int
            ?Center,i;
            ????
            ????
            if (Left? ==
            ?Right)
            ????????
            if (A[left]? > ? 0 )???? return
            ?A[left];
            ????????
            else ???? return ? 0
            ;
            ????????????
            ????Center?
            = ?(Left? + ?Right)? / ? 2
            ;
            ????MaxLeftSum?
            =
            ?MaxSubSum(A,Left,Center);
            ????MaxRightSum?
            = ?MaxSubSum(A,Center? + ? 1
            ,Right);
            ????
            ????MaxLeftBorderSum?
            = ? 0
            ;
            ????LeftBorderSum?
            = ? 0
            ;
            ????
            for (i? = ?Center;i? >= ?Left;i --
            )
            ????
            {
            ????????LeftBorderSum?
            +=
            ?A[i];
            ????????
            if (LeftBorderSum? > ?MaxLeftBorderSum)????MaxLeftBorderSum? =
            ?LeftBorderSum;
            ????}

            ????
            ????MaxRightBorderSum?
            = ? 0 ;
            ????RightBorderSum?
            = ? 0
            ;
            ????
            for (i? = ?Center? + ? 1 ;i? <= ?Right;i ++
            )
            ????
            {
            ????????RightBorderSum?
            +=
            ?A[i];
            ????????
            if (RightBorderSum? > ?MaxRightBorderSum)????MaxRightBorderSum? =
            ?RightBorderSum;
            ????}

            ????
            ????
            return ?Max3(MaxLeftSum,MaxRightSum,MaxLeftBorderSum? + ?MaxRightBorderSum);
            }


            int ?MaxSubsequenceSum( const int??A[],int ?N)
            {
            ????
            return ?MaxSubSum(A, 0 ,N? - ? 1
            );????
            }
            時間O(N),算法四
            intMaxSubsequenceSum( const int ?A[], int ?N)
            {
            ????
            int ?ThisSum,MaxSum,i;
            ????
            ????ThisSum?
            = ?MaxSum? = ? 0 ;
            ????
            for (i? = ? 0 ;i? < ?N;i ++ )
            ????
            {
            ????????ThisSum?
            += ?A[i];
            ????????
            if (ThisSum? > ?MaxSum)
            ????????????MaxSum?
            = ?ThisSum;
            ????????
            else
            ????????????ThisSum?
            = ? 0 ;
            ????}

            ????
            ????
            return ?MaxSum;
            }


            參考《數據結構與算法分析》

            posted @ 2007-02-07 10:52 Dain 閱讀(1065) | 評論 (7)編輯 收藏

            2007年1月31日 #

            編寫遞歸四條基本法則

            1. 基準情形。必須要有某些基準情形,它無須遞歸就能解出,也就是要有退出遞歸的條件。
            2. 不斷推進。對于那些需要遞歸求解的情形,每一次遞歸調用都必須要使求解狀況朝接近基準情形的方向推進。
            3. 設計法則。假設所有的遞歸調用都能運行。
            4. 合成效益。求解一個問題的同一個實例時,切勿在不同的遞歸調用中做重復性的工作。

            posted @ 2007-01-31 21:03 Dain 閱讀(444) | 評論 (0)編輯 收藏

            讀書計劃

            遇到了好多不能解決的問題后,覺得應該重新讀讀書了
            最近買了幾本書
            《More?Effective?CPP》
            《Effective?STL》
            《并行程序設計》
            《數據結構與算法分析——C語言描述》
            ?

            posted @ 2007-01-31 20:07 Dain 閱讀(459) | 評論 (1)編輯 收藏

            2007年1月19日 #

            引用和指針參數的關系

            兩種參數都允許函數修改實參指向的對象,都允許有效地向函數傳遞大類型對象。所以怎么樣決定把函數參數聲明成引用還是指針呢?
            引用必須被初始化為指向一個對象,一旦初始化了,它就不能再指向其他對象。指針可以指向一系列不同的對象也可以什么都不指向。
            因為指針可能指向一個對象或沒有任何對象,所以函數在確定指針實際指向一個有效的對象之前不能安全解引用一個指針。如:
            class ?X;
            void ?fun(X? * x)
            {
            ??
            // ?在解引用指針之前確信它非0
            ?? if (x? != ? 0 )
            ????
            // ?解引用指針
            }
            ??
            而,對于引用參數,函數不需要保證它指向一個對象。引用必須指向一個對象,不希望向指針那樣進行解引用。如:
            class?Type;
            void?op(const?Type?&t1,const?Type?&t2);

            int?main()
            {
            ??Type?obj1;
            ??
            //?設置obj1為某個值

            ??
            //?錯誤:引用參數的實參不能為0
            ??op(obj1,0);

            ??
            //?
            ??return?0;
            }
            如果一個參數可能在函數中指向不同的對象,或者這個參數可能不指向任何對象,則必須使用指針參數。
            引用參數的一個重要用法,它允許有效地實現重載操作符的同時,還能保證用法的直觀性??梢詤⒖肌禖++ Primer》

            ps 發現書287頁的第二個程序例子是錯的

            posted @ 2007-01-19 09:56 Dain 閱讀(3226) | 評論 (1)編輯 收藏

            僅列出標題  下一頁
            精品国产日韩久久亚洲| 精品久久久噜噜噜久久久| 亚洲欧美日韩久久精品| 久久久久亚洲av综合波多野结衣| 99久久无色码中文字幕| 亚洲国产精品无码久久青草| 狼狼综合久久久久综合网| 久久国产影院| 精品九九久久国内精品| 亚洲国产精品无码久久98| 欧美黑人激情性久久| 久久香蕉一级毛片| 久久99国产精品二区不卡| 亚洲精品国产第一综合99久久| 国产精品久久久久影院色| 亚洲国产精品无码久久久久久曰| 久久国产精品-国产精品| 久久一本综合| 思思久久99热免费精品6| 久久久久国产一区二区三区| 久久婷婷五月综合色奶水99啪| 亚洲AV伊人久久青青草原| 99久久99久久精品免费看蜜桃| 欧美精品九九99久久在观看| 人人狠狠综合久久亚洲88| 久久精品国产亚洲77777| 久久九九青青国产精品| 少妇高潮惨叫久久久久久| 久久只有这精品99| 日本精品一区二区久久久| 青青青国产精品国产精品久久久久 | 婷婷伊人久久大香线蕉AV| 日本精品久久久久久久久免费| 国产AV影片久久久久久| 少妇久久久久久被弄到高潮| 国产综合精品久久亚洲| 国产精品99久久久精品无码 | 久久精品国产亚洲AV不卡| 亚洲国产综合久久天堂| 亚洲人成网站999久久久综合| 日韩中文久久|