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

            3D FPS

            1234567890

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              57 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(10)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            24點 算法

              1 #include "stdafx.h"
              2 #include <iostream>
              3 #include <functional>
              4 #include <math.h>
              5 #include <float.h>
              6 #include <string>
              7 
              8 using namespace std;
              9 
             10 #if 0
             11 
             12 double Add( double a,double b)
             13 {
             14     return a + b ;
             15 };
             16 
             17 double Sub( double a,double b)
             18 {
             19     return a - b ;
             20 };
             21 double BSub( double a,double b)
             22 {
             23     return b - a ;
             24 };
             25 
             26 double Muil( double a,double b)
             27 {
             28     return a * b ;
             29 };
             30 
             31 double Div( double a,double b)
             32 {
             33     return a / b ;
             34 };
             35 double BDiv( double a,double b)
             36 {
             37     return b / a ;
             38 };
             39 
             40 typedef double (*Fun)(double,double);
             41 
             42 //     函數:       bool   IsEqual(float   f1,   float   f2,   int   absDelta)  
             43 //     功能:把比較兩個浮點數是否近似相同  
             44 //     輸入:f1,   f2參與比較的兩個浮點數  
             45 //                               absDelta   兩個浮點數之間允許有多少個其他可以精確表達的浮點數存在,相當于相對誤差  
             46 //     輸出:       true,兩個浮點數進行相等;   false   兩個浮點數不等  
             47 //     注意:僅僅適合IEEE   32位浮點數結構  
             48 // bool   IsEqual(float   f1,   float   f2,   int   absDelta)  
             49 // {  
             50 //      int   i1,   i2;  
             51 //      i1   =   (   f1>0)     ?   ((int&)f1)     :   (   (int&)   f1   -   0x80000000   );  
             52 //      i2   =   (f2>0)     ?   ((int&)f2)     :   (   (int&)   f2   -   0x80000000   );  
             53 //      return       ((abs(i1-i2))<absDelta)   ?   true   :   false;  
             54 // 
             55 // } 
             56 
             57 
             58 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
             59 
             60 int _tmain(int argc, TCHAR* argv[])
             61 {
             62 
             63 
             64     Fun vfun[6= {Add,Sub,Muil,Div,BSub,BDiv};
             65     std::string str[6]  = {"+","-","*","/","被-","被/"};
             66     //int   av[4] = {1,5,5,5};
             67     int   av[4= {8,8,3,3};
             68     //int av[4] = {11,13,7,4};
             69     //int av[4] = {8,3,1,1};
             70 
             71 
             72     //cout<<IsEqual(56.342,56.342,1);
             73     //cout<<FLOAT_EQ(56.342,56.342);
             74 
             75     cout<<"\n";
             76 
             77     for(int i = 0; i < 6; i++){
             78         for(int j = 0; j < 6; j++){
             79             for(int k = 0; k < 6; k++){
             80                 for(int x1 = 0; x1 <4; x1 ++){
             81                     for(int x2 = 0; x2 <4; x2 ++){
             82                         for(int x3 = 0; x3 <4; x3 ++){
             83                             for(int x4 = 0; x4 <4; x4 ++)
             84                             {
             85                                  if(x1 != x2 && x1 != x3 && x1 != x4
             86                                      && x2 != x3 && x2 != x4 && x3 != x4)
             87                                 {
             88                                     double sum1 =  (vfun[i])(av[x1], av[x2]) ;
             89                                     double sum2 =  (vfun[j])(sum1 ,av[x3] ) ;
             90                                     double sum3 =  (vfun[k])(sum2,av[x4] ) ;
             91                                     //if( fabs(sum3-24.0f) < 0.01f)
             92                                     if( sum3 - 24.00 < 0.01 && 24.00 - sum3 < 0.01)
             93                                     {
             94                                         cout << av[x1] <<str[i] << av[x2] <<"="<< sum1<<"\n";
             95                                         cout << sum1 <<str[j] <<  av[x3]<<""<<sum2<<"\n";
             96                                         cout << sum2 <<str[k] << av[x4]<<"="<<sum3<<"\n";
             97                                         cout <<"\n";
             98                                         goto outfor7;
             99                                     }
            100 
            101                                 }
            102                             }
            103                         }
            104                     }
            105                 }
            106             }
            107         }
            108     }
            109     cout<<"imposbat";
            110 
            111 outfor7:
            112 
            113 
            114     cin.get();
            115 
            116     return 1;
            117 }
            118 #endif

            函數對象
              1 #include "stdafx.h"
              2 #include <iostream>
              3 #include <functional>
              4 #include <boost/array.hpp>
              5 #include <boost/function.hpp>
              6 
              7 using namespace std;
              8 using namespace boost;
              9 
             10 template<class _Ty>
             11 struct nminus
             12     : public binary_function<_Ty, _Ty, _Ty>
             13 {    // functor for operator-
             14     _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
             15     {    // apply operator- to operands
             16         return (_Right - _Left);
             17     }
             18 };
             19 
             20 template<class _Ty>
             21 struct ndivides
             22     : public binary_function<_Ty, _Ty, _Ty>
             23 {    // functor for operator/
             24     _Ty operator()(const _Ty& _Left, const _Ty& _Right) const
             25     {    // apply operator/ to operands
             26         return (_Right / _Left);
             27     }
             28 };
             29 
             30 
             31 inline int GetExpoBase2(double d)
             32 {
             33     int i = 0;
             34     ((short *)(&i))[0= (((short *)(&d))[3& (short)32752); // _123456789ab____ & 0111111111110000
             35     return (i >> 4- 1023;
             36 }
             37 
             38 bool Equals(double d1, double d2)
             39 {
             40     if (d1 == d2)
             41         return true;
             42     int e1 = GetExpoBase2(d1);
             43     int e2 = GetExpoBase2(d2);
             44     int e3 = GetExpoBase2(d1 - d2);
             45     if ((e3 - e2 < -48&& (e3 - e1 < -48))
             46         return true;
             47     return false;
             48 }
             49 
             50 int _tmain(int argc,_TCHAR* argv[])
             51 {
             52     //cout<<plus(1,5);
             53     //error plus 是一個類!!!
             54     {
             55         boost::function<double (double,double)> fun;
             56 //         fun = negate< minus<double>() >();        
             57 //        cout<< (negate<double>())(  (minus<double>())(2,89) );
             58         //cout<<fun(2,89)<<"\n";        
             59     }
             60     
             61     {
             62         array< function<double (double,double )> ,6> funlist = 
             63         { plus<double>() , minus<double>() ,multiplies<double>() , divides<double>(), nminus<double>(), ndivides<double>() };
             64         array<std::string,6> name = {"+","-","*","/","b_","b/"};
             65         array<double,4> num= {5,3,3,3};
             66         //array<double,4> num= {5,5,5,1};
             67         //array<double,4> num= {8,8,3,3};
             68         //array<double,4> num= {8,3,3,3};
             69 
             70         for(int i = 0; i < funlist.size(); i++){
             71             for(int j = 0; j < funlist.size(); j++){
             72                 for(int k = 0; k < funlist.size(); k++){
             73                     for(int x1 = 0; x1 <4; x1 ++){
             74                         for(int x2 = 0; x2 <4; x2 ++){
             75                             for(int x3 = 0; x3 <4; x3 ++){
             76                                 for(int x4 = 0; x4 <4; x4 ++){
             77                                      if(x1 != x2 && x1 != x3 && x1 != x4
             78                                          && x2 != x3 && x2 != x4 && x3 != x4)
             79                                      {
             80                                          double sum1 =  funlist[i](  num[x1], num[x2]) ;
             81                                          double sum2 =  funlist[j](  sum1, num[x3]);
             82                                          double sum3 =  funlist[k]( sum2,num[x4]);
             83 
             84                                         double sum4 = funlist[i](  num[x1], num[x2]) ;
             85                                         double sum5 =  funlist[j](  num[x3], num[x4]);
             86                                          double sum6 =  funlist[k](  sum4, sum5 );
             87 
             88 //                                         static int ncoutstep = 0;
             89 //                                         ncoutstep++;
             90 //                                         cout<<sum3<<" ";
             91 //                                         if(ncoutstep % 7 == 0)
             92 //                                             cout<<endl;
             93 
             94                                         if( Equals(sum3,24.0|| sum3 == 24 )
             95                                         {
             96                                             cout << num[x1] <<name[i] << num[x2] <<"="<< sum1<<"\n";
             97                                             cout << sum1 <<name[j] <<  num[x3]<<""<<sum2<<"\n";
             98                                             cout << sum2 <<name[k] << num[x4]<<"="<<sum3<<"\n";
             99                                             cout <<"\n";
            100                                             goto outfor7;
            101                                         }        
            102 
            103                                         if( Equals(sum6,24.0|| sum6 == 24 )
            104                                         {
            105                                             cout << num[x1] <<name[i] << num[x2] <<"="<< sum4<<"\n";
            106                                             cout << num[x3] <<name[j] <<  num[x4]<<""<<sum5<<"\n";
            107                                             cout << sum4 <<name[k] << sum5 <<"="<<sum6<<"\n";
            108                                             cout <<"\n";
            109                                             goto outfor7;
            110                                         }        
            111 
            112                                     }
            113                                 }
            114                             }
            115                         }
            116                     }
            117                 }
            118             }
            119         }
            120         cout<<"imposbat";
            121 outfor7:
            122 ;
            123     }
            124     cin.get();
            125     return 1;
            126 }

            24點算 exe
            函數對象的版本更正確些

            posted on 2010-04-05 14:16 DK_jims 閱讀(234) 評論(0)  編輯 收藏 引用
            免费国产99久久久香蕉| 嫩草伊人久久精品少妇AV| 老色鬼久久亚洲AV综合| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 99久久久精品| 久久国产精品99精品国产| 久久久久久久97| 久久精品国产福利国产秒| 久久精品一区二区国产| 久久青青草原国产精品免费| 国产精品久久久久天天影视| 亚洲精品乱码久久久久久蜜桃不卡 | 麻豆一区二区99久久久久| 亚洲精品无码久久久久| 久久精品人人做人人爽97 | 婷婷五月深深久久精品| 久久久久人妻一区精品性色av| 国产精品久久精品| 久久国产精品一区| 日本五月天婷久久网站| 久久国产高潮流白浆免费观看| 日本免费一区二区久久人人澡| 欧美久久精品一级c片片| 久久强奷乱码老熟女| 亚洲va久久久噜噜噜久久天堂| 色欲综合久久中文字幕网| 国内精品久久久久久久coent| 欧美日韩精品久久久久| 亚洲中文字幕无码久久综合网| 国内精品久久久久久99蜜桃| 国产香蕉97碰碰久久人人| 狠狠色综合网站久久久久久久高清| 国产精品久久久久国产A级| 日韩一区二区三区视频久久| 久久66热人妻偷产精品9| 久久亚洲国产精品123区| 久久精品无码专区免费青青| 久久综合一区二区无码| 色综合久久中文色婷婷| 久久久婷婷五月亚洲97号色| 久久精品中文字幕第23页|