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

            newplan

            阿基米德在洗澡時發現浮力原理,高興得來不及穿上褲子,跑到街上大喊:Eureka(我找到了)。
            posts - 39, comments - 26, trackbacks - 0, articles - 4
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            2008年12月21日

                 摘要: import java.io.BufferedReader;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import&...  閱讀全文

            posted @ 2008-12-21 20:38 山泉彎延 閱讀(3390) | 評論 (0)編輯 收藏

            2008年12月13日

            import java.util.concurrent.ExecutorService;
            import java.util.concurrent.Executors;
            import java.util.concurrent.ScheduledExecutorService;
            import java.util.concurrent.ScheduledFuture;
            import java.util.concurrent.TimeUnit;


            /*
             * 學習使用JDK5以上的線程池操作
             
            */


            public class ThreadPool {

                
            public static void main(String[] args)
                
            {
                        
            /*
                         * 可以安排線程運行時間
                         * 
                         
            */

                    
                        
            final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
                        
            final Runnable beeper = new Runnable() 
                        
            {     
                            
            int count = 0
                            
            public void run() 
                            
            {        
                                System.out.println( 
            " beep " + (++count));
                                
                            }
                
                        }
            ;
                        
            final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate(beeper, 12,TimeUnit.SECONDS);
                        
                        scheduler.schedule(
            new Runnable() 
                                            
            {      
                                                
            public void run()
                                                
            {        
                                                    beeperHandle.cancel(
            true);   
                                                    scheduler.shutdown();
                                                }
                
                                            }
            200, TimeUnit.SECONDS
                                            );
                        
            /*
                         * 不可以安排線程的運行時間
                         
            */

                        ExecutorService    exec 
            = Executors.newFixedThreadPool(2);    
                        
            for(int index = 0; index < 200; index++
                        
            {
                            Runnable run 
            = new Runnable()
                            
            {
                                
            public void run() 
                                
            {   long time =(long)(Math.random() * 1000);
                                    System.out.println(
            "Sleeping " + time + "ms");
                                    
            try 
                                        Thread.sleep(time);
                                        }
             catch (InterruptedException e)
                                        
            {           
                                            
                                        }
                    
                                }

                            }
            ;
                            exec.execute(run);    
                        }

                        exec.shutdown();  
                
                }

                
                
            }

            posted @ 2008-12-13 19:04 山泉彎延 閱讀(740) | 評論 (0)編輯 收藏

            2008年10月16日


            #include 
            <iostream>
            #include 
            <String>
            using namespace std;
            class ia{
                  
            public:
                  ia(
            string a){this->a=a;}
                  
            ~ia(){cout<<"~"<<a<<endl;getchar();}
                  
            private:
                          
            string a;
                  };
            int main()
            {
                auto_ptr
            <ia> ap(new ia("newplan"));
                ia 
            *bp = new ia("zhaoziming");
                
            return 1;
            }

            posted @ 2008-10-16 20:12 山泉彎延 閱讀(865) | 評論 (0)編輯 收藏

            2008年9月17日

            /*
            bash myshell.sh
            */
            echo "doing jobs...."
            yacc -d  b3.y
            lex   b3.l
            cc lex.yy.c  y.tab.c -o b3
            echo "jobs end."

            posted @ 2008-09-17 00:05 山泉彎延 閱讀(500) | 評論 (1)編輯 收藏

            /*
            編譯原理實驗3
            B3.L
            */
            %{
            #include"y.tab.h"
            #include<string.h>
            extern FILE * yyin;
            extern FILE * yyout;
            extern int yylineno;
            %}

            delim      [  \t]
            ws           {delim}+
            letter       [A-Za-z]
            digit        [0-9]
            id           {letter}({letter}|{digit})*
            number       {digit}+
            addop        [+-]
            mulop        [*/]
            %%
            \r\n         {yylineno++;}
            {ws}         {/*d*/}
            while        {return WHILE;}
            do           {return DO;}
            if           {return IF;}
            else         {return ELSE;}
            for          {return FOR;}
            int          {return INT;}
            char         {return CHAR;}
            void         {return VOID;}
            return       {return RETURN;}
            \'[a-zA-Z0-9]\'    {strcpy(yylval._ident,yytext);return CONST_CHAR;}
            \"[a-zA-Z]+\" {strcpy(yylval._ident,yytext);return STRING;}
            {id}         {strcpy(yylval._ident,yytext);return ID;}
            {number}     {strcpy(yylval._ident,yytext);return NUM;}
            "["          {return '[';}
            "]"          {return ']';}
            "<"          {return LT;}
            "="          {return '=';}
            ">"          {return GT;}
            "<="         {return LE;}
            ">="         {return GE;}
            "!="         {return NE;}
            "=="         {return EQ;}
            {addop}      {yylval._op=yytext[0]; return ADDOP;}
            {mulop}      {yylval._op=yytext[0]; return MULOP;}
            ";"          {return ';';}
            "{"          {return '{';}
            "}"          {return '}';}
            "("          {return '(';}
            ")"          {return ')';}
            ","          {return ',';}
            %%
            int yywrap(){
               return 1;
            }

            posted @ 2008-09-17 00:01 山泉彎延 閱讀(374) | 評論 (0)編輯 收藏

            /*
            編譯原理實驗三實驗代碼
            B3.Y
            newplan
            08-09-16
            */
            %{
            /*-----------head file---------*/
            #include <ctype.h>
            #include <string.h>
            #include <stdio.h>
            #include <stdlib.h>
            #include <assert.h>
            /*-----------macros------------*/
            #define  HASHSIZE  128
            #define _INT  34
            #define _CHAR 35
            #define _VOID 36
            #define _STRING 37
            #define _FUNC_TYPE 38
            #define _ERROR 39
            extern  int yylex();
            extern  FILE*  yyin;
            extern  FILE*  yyout;
            int     yylineno;

            typedef struct {
            int a[5];
            int n;
            int h;
            int ret_type;
            }param;
            /*¶¨Òå±êʶ·û*/
            typedef struct {
            char name[10];
            int  scope;/*ËùÔڵIJã´Î*/
            int  type;/*±êʶ·ûÀàÐÍ*/
            param  *p;
            }symbol;

            /*¶¨ÒåhashͰ*/
            struct sym_entry{
            symbol sym;
            struct sym_entry  *next ;
            };

            /*¶¨ÒåhashÁ´±í*/
            struct table {
            int level ;
            struct table *previous;
            struct  sym_entry  *buckets[HASHSIZE] ;
            };

            int    table_len = 0;/*ÓжàÉÙ¸ö±í*/
            struct table *table_stack[100];/*±íÕ»*/
            struct table *global_table ;/*È«¾Ö±íÖ¸Õë*/
            param  *global_func_p;
            int    level  = 0 ;/*È«¾Ö²ã´ÎÉèÖÃΪ 0 */
            int    error  = 0;
            int    trace  = 0;

            /*hash º¯Êý*/
            int hash(char *s)
            {
              char *p ;
              unsigned h = 0,g=0;
              for(p=s ;*p != '\0' ;p++)
               {
               h=(h<<4)+(*p) ;

               if(g=h & 0xf0000000)
               {
               h=h^(g>>24);
               h=h^g;
               }
               }
              return h%128;
            }
            /*----------------²éÕÒ·ûºÅ±í------------------*/
            symbol *lookupall(char *name,struct table *tp)
            {
              int  h =hash(name);
              struct sym_entry *p = NULL;
              int tag=0;
              do
              {
               if(tp->level ==level && tag >0 )continue;
               for(p = tp->buckets[h];p;p=p->next)
               if(!strcmp(name,p->sym.name)) return &p->sym ;
               tag = 1 ;
              }
              while(tp=tp->previous);
              return  NULL;
            }
            /*---------------------------------------------*/
            symbol *lookup(char *name,struct table *tp)
            {
            int h= hash(name);
            struct sym_entry *p =NULL;
            for(p = tp->buckets[h];p;p = p->next)
               if(!strcmp(name,p->sym.name)){return  &p->sym ;}

            return  NULL;
            }

            /*---------------´´½¨Ò»¸ö·ûºÅ±í----------------*/
            struct table * mktable(struct table *previous ,int level)
            {
            struct table *new =(struct table *)malloc(sizeof *new);
            new->previous = previous ;
            new->level = level ;
            int  i;
            for(i= 0; i<HASHSIZE ;i++)new->buckets[i]=0;
            return new;
            }


            /*---------------²åÈëÒ»¸ö±êʶ·û----------------*/
            symbol *insert(char *name,struct table *tpp)
            {
            int h = hash(name);
            struct  table *tp = tpp;
            struct  sym_entry *p =(struct sym_entry *)malloc(sizeof *p);
            if(tp->level<level)
            {
            tp =(struct table *)mktable(tp,level);
            table_stack[table_len] = tp ;
            table_len ++;
            }
            strcpy(p->sym.name,name);
            p->sym.scope= level;
            p->sym.type = 0;
            p->next = tp->buckets[h];
            tp->buckets[h]=p;
            return  &p->sym ;
            }

            %}
            %start program
            %right '='
            %left ADDOP
            %left '*' '/'
            %left LE LT GT GE EQ NE
            %union {char _ident[9]; int value;char _op;};
            %token <_ident> ID 
            %token NUM
            %token <_ident> STRING
            %token IF
            %token ELSE
            %token WHILE
            %token INT
            %token CHAR
            %token <_ident> CONST_CHAR
            %token VOID
            %token RETURN
            %token FOR
            %token DO
            %token <_op>     ADDOP
            %type  <value>   type_specifer
            %type  <value>   var
            %type  <value>   factor
            %type  <value>   term
            %type  <value>   additive_expression
            %type  <value>   simple_expression
            %type  <value>   expression
            %type  <value>   arg_list
            %token  <_op>    MULOP
            %nonassoc IFX
            %nonassoc ELSE
            %%
            program         :  M    declaration_list {if(1 == trace)printf("program ==> M declaration_list.\n");if(error == 0 ) fprintf(yyout,"no error\n");}
              ;
            M               : {
                             global_table = mktable(NULL,0);
                             table_stack[table_len] = global_table ;
                             table_len++;
                           }
                            ;
            declaration_list: declaration_list declaration
            {
             if(trace == 1) fprintf(yyout,"declaration_list ==> declaration_list  declaration.\n");
            }
              | declaration
            {
             if(trace == 1) fprintf(yyout,"declaration_list ==> declaration.\n");
            }
                           ;
            declaration     :var_declaration
            {
            if (trace ==1) fprintf(yyout,"declaration ==> var_declaration.\n");
            }
                            |fun_declaration
            {
            if (trace ==1) fprintf(yyout,"declaration ==> fun_declaration.\n");
            }
                            ;
            var_declaration :type_specifer ID ';'
                            {
                              if(trace == 1) printf("var_declaration ==>type_specifer ID.\n");
                              struct table *tp = table_stack[table_len-1];
                              if(lookup($2,tp) == NULL)
                             {
                              symbol *p = insert($2,tp);
                              p->type = $1 ;
                             }
                             else {error = 1 ; fprintf(yyout, "line %d:error:%s:redefinition\n ",yylineno,$2);}
                            }
                            |type_specifer ID '[' NUM ']' ';'
                            ;
            type_specifer   :INT {$$ =_INT ;}             
                            |CHAR {$$ = _CHAR;}
                            |VOID {$$ =_VOID ;}
                            ;
            fun_declaration :type_specifer  fun_tag '('  LL  params ')' compound_stmt {level--;}
                            |type_specifer  fun_tag '('  LL  params ')' ';'{level--;}
                            ;
            fun_tag         : ID
            {
              struct table *tp = table_stack[table_len-1];
              symbol *tmp ;
              tmp = lookupall($1,tp);
              if(tmp == NULL)
              {tmp =insert($1,tp);
               global_func_p = tmp->p = (param *)malloc(sizeof(*tmp->p));
               global_func_p->n =0 ;
               global_func_p->ret_type = _INT ;
               tmp->type =_FUNC_TYPE;
              }
              else
              {error = 1 ; fprintf(yyout,"line %d:error %s redefine of function.\n",yylineno,$1);}
            }
                            ;
            LL:             {level++;
                             struct table *tp = mktable(table_stack[table_len-1],level);
                             table_stack[table_len]=tp;
                             table_len++;
                             if(1==trace)printf("level = %d \n",level);
                            }
                            ;
            params          :param_list
                            |VOID{global_func_p->n = 0; if(1 == trace)printf("params==>void\n");}
                            ;
            param_list      :param_list ',' param {if(1 ==trace )printf("param_list ==> param_list , param.\n");}
                            |param
                            ;
            param           :type_specifer ID
                            {
                               struct table *tp =table_stack[table_len-1];
                               symbol *p =insert($2,tp);
                               p->type =$1;
                               global_func_p->a[global_func_p->n++]= $1 ;
                            //   printf("type[%d]=%d\n",global_func_p->n-1,global_func_p->a[global_func_p->n-1]);
                             }
                            ;
            compound_stmt   :'{' local_declarations statement_list '}'
                            ;
            local_declarations:  local_declarations var_declaration{if(1 ==trace )printf("local_declarations ==>loacal_declarations var_declaration\n");}
              |{if(1 == trace )printf("local_declarations ==>  .\n");}
                            ;
            statement_list  :statement_list statement
                            |{}
                            ;
            statement       :expression_stmt{if(1 == trace )printf("statement ==> expression_stmt.\n");}
                            |if_stmt
                            |compound_stmt
                            |while_stmt
                            |return_stmt             
            ;
            expression_stmt :expression ';'
                            |';'
                            ;
            if_stmt         :IF '(' expression ')' statement %prec IFX {if(1== trace)printf("if_stmt ==> if expression statement .\n");}
                            |IF '(' expression ')' statement ELSE statement
            {if(1==trace )printf("if_Stmt ==> if expression statement else statement.\n");}                 ;
            while_stmt      :WHILE '(' expression ')' statement
                            ;
            return_stmt     :RETURN ';'
                            |RETURN expression ';'
                            ;
            expression      :var '=' expression{if($1 != $3){error =1 ;printf("line %d:  '='  must be same type.\n",yylineno);}if(1 == trace )printf("expression ==>var = expression.\n");}
                            |simple_expression {$$  ==  $1 ;}
                            ;
            var             :ID {
                                 symbol *p = lookupall($1,table_stack[table_len-1]);
                               
                                 if(NULL==p){$$ = _ERROR ;error =1 ;fprintf(yyout,"line %d undeclared identifier %s\n",yylineno,$1);}
                                 else
                                 $$ =p->type ;
                               
                               }
                            ;
            simple_expression:additive_expression relop additive_expression{if($1==_INT && $3 ==_INT || $1 ==_CHAR && $3 == _CHAR){;}else{ error =1 ;printf("line %d :relop must int int or char char.\n",yylineno);}}
                             |additive_expression{$$ =$1 ;}
                             ;
            relop            :LE
                             |LT
                             |GT
                             |GE
                             |EQ
                             |NE
            ;
            additive_expression:additive_expression ADDOP term {if($1 == _INT && $3 ==_INT){;}else{error =1 ;printf("line%d :addop must int int .\n",yylineno);}if(1==trace)printf("additive_expression ==>additive_expression ADDOP term.\n");}
                            |term{$$ = $1 ;}
                            ;
            term            :term MULOP factor {if($1==_INT && $3 ==_INT ){;}else{error = 1 ;printf("\nline%d :mulop must int int.\n",yylineno);}}
              |factor {$$ =$1;}
              ;
            factor          :'(' expression ')'
              |var {$$ = $1;}
              |call{if(global_func_p){$$=global_func_p->ret_type;}}
              |NUM {$$ = _INT;}
                            |STRING {$$ =_STRING;}
                            |CONST_CHAR {$$ = _CHAR ;}
              ;
            call  :ID { symbol *tmp =lookupall($1,table_stack[table_len-1]);if(NULL ==tmp||tmp->type!=_FUNC_TYPE){error =1;printf("line%d :undeclared identifier %s.\n",yylineno,$1);}else {global_func_p = tmp->p;global_func_p->h = 0;}
            } '(' args ')' {if(1 == trace )printf("call ==> ID args .\n");}
              ;
            args  :arg_list{if(global_func_p->n > global_func_p->h){error=1;printf("line%d :param num error.\n",yylineno);}}
              |{if(global_func_p->n != 0){error =1 ;printf("line%d :param error.\n",yylineno);}}
              ;
            arg_list        :arg_list ',' expression{if(global_func_p->n<=global_func_p->h){error=1 ;printf("line%d :param num error.\n",yylineno);}else if(global_func_p->a[global_func_p->h]!=$3){error =1 ;printf("line%d :param error %d.\n",yylineno,$3);}else{global_func_p->h++;}}
              |expression {$$ =$1 ; if(global_func_p->a[global_func_p->h]!=$1){error =1 ;printf("line%d :param error $1=%d.\n",yylineno,$1);}else{global_func_p->h++;}}

              ;

            %%
            int main(int argc,char *argv[])
            {
                  printf("start checking...\n");
                  yylineno=1;
                  if(argc==3)
                  {
              yyin=fopen(argv[1],"r");
                     yyout=fopen(argv[2],"w");
                  }
                  else if(argc==2)
             { yyin=fopen(argv[1],"r");
                            yyout = stdout ;
                    }
                  yyparse();
                  return 0;
            }
            int yyerror(char *string)
            {
                 printf("error:%s in line %d\n",string,yylineno);
                 return 0;
            }

            posted @ 2008-09-17 00:00 山泉彎延 閱讀(422) | 評論 (0)編輯 收藏

            2008年6月24日

            function[]=iqr()
            % 實驗名稱:方陣的QR分解
            % 實驗描述:先將方陣化為上海申博格陣,再用QR分解法求上海申博格陣的特征值,則所得到的特征值也是方陣的特征值
            % 作者:newplan
            % 實驗完成日期:6月10號
            %下面的A為測試三階的方陣
            A
            =[5,-3,2;6,-4,4;4,-4,5]
            %下面的A為測試四階的方陣
            %A 
            = [1 2 1 2;2 2 -1 1;1 -1 1 1;2 1 1 1]
            %通過調用malab的自帶的函數求得A的所有特征值和特征向量
            %特征值保存在v中,特征向量保存的在d中,將其打印出來和我們的算法算出來的特征值進行對比
            [v,d]
            =eig(A)
            %求出行和列的大小
            msize
            =size(A);
            %取得矩陣的列數,其實行數和列數都為n
            n
            =msize(1);
            %生成n階單位陣
            Q
            =eye(n);
            %用household的方法求矩陣A的上海森伯格陣
            for i=1:n-2%從第一列開始到倒數第三列 
                %求出每一列的最大值
                d
            =max(abs(A(i+1:n,i)));
                %規范化
                U(i
            +1:n,i)=A(i+1:n,i)/d;
                delta
            =U(i+1,i)*norm(U(i+1:n,i))/abs(U(i+1,i));
                U(i
            +1,i)=U(i+1,i)+delta;
                beta 
            = delta*U(i+1,i);
                %求出R矩陣根據課本316P例題三 
                R 
            = eye(n-i,n-i)-inv(beta)*U(i+1:n,i)*U(i+1:n,i)';
                u=eye(n,n);
                
            for j =i+1:n
                    
            for k =i+1:n
                        u(j,k)
            =R(j-i,k-i);
                    
            end
                
            end
                A
            =u*A*u;%生成新的A=u×A×u
            end
            %error為我們設定的誤差限制
            error = 0.0000001;
            %flag為判斷QR法是否繼續進行的標志位
            flag 
            =1;
            while flag==1
            flag 
            =0 ;
            =A;
            = eye(n,n);
            %按照QR分解法求出cos,
            sin 然后計算V,最終得到R和Q
            for i=1:n-1
              r 
            = norm(R(i:i+1,i));
              icos
            =R(i,i)/r;
              isin
            =R(i+1,i)/r;
              v
            =eye(n,n);
              v(i,i)
            =icos;
              v(i
            +1,i+1)=icos;
              v(i,i
            +1)=isin;
              v(i
            +1,i)=-isin;
              R
            =v*R;
              Q
            =Q*v';
            end
            %用R
            *Q的結果去替換A
            =R*Q;
            %下面這個循環檢測A的精度時候足夠,去看A的次對角線各個元素的絕對值是否小于誤差限制
            for w =2:n
                 
            if abs(A(w,w-1))>error
                 flag 
            = 1 ;
                 break;%若有其中一個元素的絕對值還是大于誤差限制則還要繼續進行QR分解
                
            end   
            end
            %判斷的過程完畢
            end
            %把A打印出來
            A



            posted @ 2008-06-24 10:52 山泉彎延 閱讀(2480) | 評論 (0)編輯 收藏

            2008年6月10日

            /*
            6.10
            */
            /*==========INCLUDES BEGIN===============*/ 
            #include 
            <cstdlib>
            #include 
            <iostream>
            #include 
            <fstream>
            #include 
            <algorithm>
            #include 
            <QApplication>
            #include 
            <QWidget>
            #include 
            <QPainter>
            #include 
            <Qt>

            /*==========INCLUDE END==================*/ 

            /*==========MACROS BEGIN=================*/
            #define  MAX        
            100000000
            #define  BUFFER     
            300
            #define  INPUTFILE  
            "./50.txt"
            /*==========MACROS  END==================*/

            /*==========STD DECLRARS BEGIN===========*/
            using std::cout;
            using std::cin;
            using std::endl;
            using std::ios;
            using std::ifstream;
            using std::sort;
            using std::max;
            /*==========STD DECLARS END===============*/

            /*============STRUCTS BRGIN===============*/ 
            struct 
            Space {
                   
            int x;
                   
            int y;
                   
            int w;
                   
            int h;
                   bool v;
            //IF VISITED THEN V =TURE ELSE FLASE
                   };
            struct Gadget
            {
                   
            int x;
                   
            int y;
                   
            int w;
                   
            int h;
            };
            /*=============STRUCT END=================*/



            /*===========GADGET CUT BEGIN=============*/ 
                    Gadget  result[BUFFER];
                    Gadget  g[BUFFER];
                    
            int      bestH;
                    
            Space   space[BUFFER];
                    
            int spaceNum ;
                    
            int     W;
                    
            int     N;
                    
            int     H;  
                    ifstream Fin; 
                    
            int     deep;   
                    clock_t    start;
                    clock_t     
            end;

            /*-------------FRIENDS METHOD--------------------*/
            bool mycmpG(Gadget t1,Gadget t2){return t1.h
            >t2.h;} 
            /*-------------FRIENDS METHOD--------------------*/
             bool mycompS(
            Space t1,Space t2){return t1.y<t2.y;}
            /*-------------CONSTRUCT METHOD------------------*/
            void init()
            {   
                Fin.open(INPUTFILE,ios::in);
                Fin
            >>N;
                Fin
            >>W;
                
            for(int i=0;i<N;i++)
                  Fin
            >>g[i].h>>g[i].w;
                sort(g,g
            +N,mycmpG);
                
                
            space[0].x=space[0].y=0;
                
            space[0].h=MAX;
                
            space[0].w=W;
                
            for(int i=0;i<N;i++)
                  
            space[0].v=false;
                H
            =0;
                deep
            =0
                bestH 
            = MAX;
                spaceNum 
            = 1
            }   
            /*-------------CUT METHOD------------------*/
            bool canBeCut(Gadget 
            &g,int i,int &TaddSpace)
            {
                
            int addSpace = 0;    
                
            if((space[i].h>=g.h)&&(space[i].w>=g.w)){
                    
            if(space[i].w>g.w){
                        
            space[spaceNum].x = space[i].x+g.w;
                        
            space[spaceNum].y = space[i].y;
                        
            space[spaceNum].h = g.h;
                        
            space[spaceNum].w = space[i].w - g.w;
                        addSpace
            ++;
                    }
                    
            if(space[i].h>g.h){
                        
            space[spaceNum+1].x = space[i].x;    
                        
            space[spaceNum+1].y = space[i].y+g.h;
                        
            if(space[i].h==MAX)
                            
            space[spaceNum+1].h = MAX;
                        
            else
                            
            space[spaceNum+1].h = space[i].h - g.h;
                        
            space[spaceNum+1].w = space[i].w;
                        addSpace
            ++;
                    }
                    g.x 
            = space[i].x;
                    g.y 
            = space[i].y;
                    H 
            = max(H,g.y+g.h);
                    spaceNum 
            += addSpace;
                    TaddSpace 
            = addSpace;
                    return 
            true;
                }
                return 
            false;
            }
            /*-------------THE MAIN METHOD--------------------*/
             void backTrack(
            int which)
            {   
            // if(deep==100000)return;
                
            // else deep++;
                 sort(
            space,space+spaceNum,mycompS);
                 
            Space   temp[BUFFER];
                 
            for(int i=0;i<spaceNum;i++)
                    temp[i] 
            = space[i];    
                 
                 
            if(which==N)
                  {
                    
            if(H<bestH)
                    {    bestH 
            = H;
                        
            for(int i = 0;i<N;i++)
                          result[i]
            =g[i];
                       
                    }
                    return;
                  }
                 
            int addSpace;
                 
            int Num=spaceNum;     
                 
            for(int i=0;i<Num;i++)
                     
            if(space[i].v == false)
                      { 
                        
            int tempH=H;
                        
            if(canBeCut(g[which],i,addSpace))
                        {       
                                
            if(H>bestH)//剪枝 
                                {
                                 H 
            = tempH;
                                 spaceNum 
            -= addSpace;
                                 continue;
                                }
                                
            space[i].v = true;
                                backTrack(which
            +1);
                                spaceNum
            -=addSpace;
                                
            space[i].v = false
                                H 
            = tempH;
                                
            for(int k=0;k<spaceNum;k++)
                                
            space[k] = temp[k];        
                         }         
                      }
                 
            }
            /*===========GADGET CUT END=============*/ 

            /*========NEWBOX CLASS BEGIN============*/
            class NEWBOX:
            public QWidget
            {   
                
            public:
                    NEWBOX(QWidget 
            *parent=0);
                protected:
                    void paintEvent(QPaintEvent 
            *event); 
                
            private:

            };
            /*NEWBOX METHOD*/
            /*-----------------------------------*/
            NEWBOX::NEWBOX(QWidget 
            *parent):QWidget(parent)
            {
                 setFixedSize(W
            *15,30*15);
                 char temp[
            5];
                 sprintf(temp,
            "%d",bestH);
                 char title[
            40]="H:";
                 strcat(title,temp);
                 char temp2[
            20]=" Spend TIME:";
                 char temp3[
            5];
                 sprintf(temp3,
            "%f",(double)(end-start)/CLOCKS_PER_SEC);
                 strcat(temp2,temp3);
                 strcat(title,temp2);
                 setWindowTitle(title);
                 setPalette(QPalette(QColor(
            250250200)));
                 setAutoFillBackground(
            true);
            }
            /*-----------------------------------*/
            void NEWBOX::paintEvent(QPaintEvent 
            *)
            {    QPainter painter(this);
                 painter.setPen(Qt::SolidLine);
                 painter.setBrush(Qt::blue);
                 painter.translate(
            0,0);
                 
            for(int i=0;i<=N;i++)
                 painter.drawRect(result[i].x
            *15,30*15-result[i].y*15,
                 result[i].w
            *15,-result[i].h*15);  
            }

            /*=========NEWBOX CLASS END=============*/

            int main(int argc, char *argv[])
            {   QApplication app(argc, argv);
                init();
                start
            =clock();
                backTrack(
            0);
                
            end= clock();//TIME END HERE
                NEWBOX newb;
                newb.show();
                return app.exec();

            }

            posted @ 2008-06-10 21:47 山泉彎延 閱讀(372) | 評論 (0)編輯 收藏

            2008年6月5日

                 摘要: /*08.6.2*//*------------------INCLUDES BEGIN---------------*/#include <cstdlib>#include <iostream>#include <fstream>#include <string>#include <...  閱讀全文

            posted @ 2008-06-05 09:05 山泉彎延 閱讀(550) | 評論 (0)編輯 收藏

            2008年5月13日

            /*
             *有N個人排隊到R個水龍頭去打水,他們裝滿水桶的時間
             *為T1,T2,…,Tn為整數且各不相等,應如何安排他們
             *的打水順序才能使他們花費的時間最少?
             *分析:由于排隊時,越靠前面的計算的次數越多,顯然越小
             *的排在越前面得出的結果越?。梢杂脭祵W方法簡單證明,
             *這里就不再贅述),所以這道題可以用貪心法解答
             */
            /*------------INCLUDES---------------*/
            #include 
            <cstdlib>
            #include 
            <iostream>
            #include 
            <queue>
            #include 
            <fstream>
            /*------------INCLUDES---------------*/

            /*---------------STD-----------------*/
            using std::ifstream;
            using std::queue;
            using std::vector;
            using std::greater;
            using std::priority_queue;
            /*---------------STD----------------*/

            /*------------GLOBAL VAL------------*/
            int  M[5];
            /*------------GLOBAL VAL------------*/

            /*---------------MAIN---------------*/
            int main(int argc, char *argv[])
            {   ifstream  Fin;
                Fin.open(
            "queue.txt");
                
                priority_queue
            <int,vector<int>,greater<vector<int>::value_type> >   iqueue;
                
                
            int a;
                
            while(Fin>>a)
                {
                   iqueue.push(a);
                }
                
                
            int flag=0;
                
            int i=0;
                
                
            while(!iqueue.empty())
                {
                  
            if(flag==0)
                  {M[i]
            =iqueue.top();
                   iqueue.pop(); 
                   i
            ++;     
                   
            if(i==5)
                   flag
            =1;
                  }
                  
            else if(flag==1)
                  {
                   M[i]
            =iqueue.top();
                   iqueue.pop(); 
                   i
            --;
                   
            if(i==0)
                   flag
            =0;    
                  }
                  
                }
                
                system(
            "PAUSE");
                return EXIT_SUCCESS;
            }
            /*---------------MAIN---------------*/

            posted @ 2008-05-13 23:48 山泉彎延 閱讀(611) | 評論 (1)編輯 收藏

            丰满少妇高潮惨叫久久久| 久久免费美女视频| 久久精品国产清自在天天线| 色欲av伊人久久大香线蕉影院| 久久国产精品免费| 91久久香蕉国产熟女线看| 狠狠干狠狠久久| 久久国产精品久久精品国产| 激情伊人五月天久久综合| 久久香蕉国产线看观看精品yw| 久久精品免费一区二区| 精品伊人久久久| 久久91精品国产91久| 久久久久久曰本AV免费免费| 久久久久久久波多野结衣高潮| 久久久久人妻一区二区三区| 国产aⅴ激情无码久久| 亚洲AV无码久久精品狠狠爱浪潮 | yellow中文字幕久久网| 久久精品国内一区二区三区| 国产高潮国产高潮久久久91| 久久久99精品成人片中文字幕| 日韩一区二区三区视频久久 | 无夜精品久久久久久| 伊人久久综合无码成人网| 久久99精品久久久久久hb无码| 久久se精品一区二区| 久久综合伊人77777| 看久久久久久a级毛片| 精品久久久久久国产牛牛app| 少妇久久久久久被弄到高潮| 一本色道久久HEZYO无码| 久久久久国产精品| 国产精品久久久久久久app| 久久99亚洲网美利坚合众国| 国产亚洲成人久久| 亚洲中文字幕无码久久2017| 久久香蕉国产线看观看乱码| 久久婷婷人人澡人人爽人人爱| 久久99中文字幕久久| 99久久国产宗和精品1上映|