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

            遞歸的非遞歸寫法

            #include<iostream>
            #include<deque>
            #include <ctime>
            using namespace std;
            template<class _Ty, class _C = deque<_Ty> >
            class zlfStack {
            public:
             typedef unsigned _Ty;
             typedef _C::allocator_type allocator_type;
             typedef _C::value_type value_type;
             typedef _C::size_type size_type;
             typedef _C::iterator zlfIterator;
            protected:
             _C c;
            public:
            inline
             const value_type& zlfTop2(){
              return *(c.end()-2);
             }
            inline
             const value_type& zlfTop3(){
              return *(c.end()-3);
             }
            inline
             void top_3(value_type& x,value_type& y,value_type& b)
             {
              b=*(c.end()-1);
              y=*(c.end()-2);
              x=*(c.end()-3);
             }
            inline
            void top_2(value_type& x,value_type& y)
            {
             y=*(c.end()-2);
             x=*(c.end()-3);
            }

             //zlfStack(){ }
             explicit zlfStack(const allocator_type& _Al = allocator_type())
              :c(_Al){}
             allocator_type get_allocator() const
             {return (c.get_allocator()); }
             bool empty() const
             {return (c.empty()); }
             size_type size() const
             {return (c.size()); }
             value_type& top()
             {return (c.back()); }
             const value_type& top() const
             {return (c.back()); }
             void push(const value_type& _X)
             {c.push_back(_X); }
            inline
             void push_3(const value_type& x,const value_type& y,const value_type& b)
             {
              c.push_back(x);
              c.push_back(y);
              c.push_back(b);
             }
            inline
             void pop()
             {c.pop_back(); }
             };///
            enum{B0=0,B1=1,B2=2,B3=3};
            int A(unsigned x,unsigned y)
            {
             static count=0; 
             if (!x&&!y) {return ++count;return count;}
             if (x==0xffff) {count=0;return 0;}
             if (x) A(--x,y);
            AB1: if(y) A(x,--y);
            AB2:
              return count;
              
            }
            inline
            void clear(){A(0xffff,0);}
            zlfStack<unsigned> s;
            inline
            void push(unsigned x,unsigned y,unsigned b)
            {
             s.push(x);
             s.push(y);
             s.push(b);
            }
            inline
            void pop(unsigned& x,unsigned& y,unsigned& b)
            {
             b=s.top();
             s.pop();
            // y=s.top();
             s.pop();
            // x=s.top();
             s.pop();
            }


            int main()
            {
             unsigned x=1,y=1,b=1,c=0,z=0;
             unsigned temp=0;
             clock_t t1,t2;
             unsigned k=1;
             unsigned long sum1=0,sum2=0,time1=0,time2=0;

             cout<<"AAAA"<<endl;
             t1=clock();
             for (x=1;x<10;x++) {
              for (y=1;y<10;y++) { 
               clear();
               k=A(x,y);
               sum1+=k;
               cout<<k<<" ";
               cout<<"x="<<x<<" "<<"y="<<y<<endl;
              }
             }
             t2=clock();
             time1=t2-t1;
             cout<<endl;


             if (!x&&!y) return 0;//exit
             sum2 = 0;
             t1=clock();
             for (x=1;x<10;x++) { 
              for (y=1;y<10;y++) {// push(x,y,B3);
              s.push_3(x,y,B3);
              c=0;
              b=B0;
              while (!s.empty()) {
               switch(b) {
               case B0:if(x) {//push(--x,y,B1);
                s.push_3(--x,y,B1);
                b=B0;continue;}
               case B1:if(y) {//push(x,--y,B2);
                s.push_3(x,--y,B2);
                b=B0;continue;}
               case B2:if (!x&&!y) c++;
               default:;
               }//switch
              // pop(x,y,b);
               b=s.top();
               s.pop();
               s.pop(); 
               s.pop();
               if(b==B3) break;//return to main
              // pop(x,y,temp);
              // push(x,y,temp);
              // y=s.zlfTop2();
              // x=s.zlfTop3();
               s.top_2(x,y);
              }//while
              sum2+=c;
             // cout<<"c="<<c<<" "<<"x="<<x<<" "<<"y="<<y<<endl;
              }//y
             }//x
             t2=clock();
             time2=t2-t1;
             cout<<"time used :"<<time2<<"ms"<<endl;
             cout<<"routines :"<<sum2<<endl;
             cout<<endl<<endl;
             double t;
             cout<<"routines: "<<sum1<<"  time1: "<<time1<<endl;
             t=sum1/time1;
             cout<<t<<" rps"<<endl;
             cout<<"routines: "<<sum2<<"  time2: "<<time2<<endl;
             t=sum2/time2;
             cout<<t<<" rps"<<endl;
             return 0;
            }

            posted on 2008-01-11 17:15 zlf 閱讀(639) 評論(0)  編輯 收藏 引用

            導航

            <2007年9月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久九九免费高清视频| 国内精品久久九九国产精品| 久久久久99精品成人片三人毛片| 久久996热精品xxxx| 国产精品亚洲综合久久| 国产产无码乱码精品久久鸭| 久久精品国产亚洲Aⅴ蜜臀色欲| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 国产69精品久久久久9999APGF| 91视频国产91久久久| 久久久久国产一级毛片高清板| 久久精品中文闷骚内射| 久久久噜噜噜久久| 国产精品99精品久久免费| 亚洲午夜久久久| 国产综合免费精品久久久| 亚洲精品乱码久久久久久蜜桃图片 | 日韩电影久久久被窝网| 97精品伊人久久大香线蕉app| 久久久午夜精品| 精品无码久久久久久久动漫| 奇米综合四色77777久久| 伊人久久五月天| 香蕉aa三级久久毛片| 久久久WWW成人免费毛片| 成人亚洲欧美久久久久| A狠狠久久蜜臀婷色中文网| 亚洲国产另类久久久精品黑人| 亚洲国产精品无码久久久久久曰| 狠狠综合久久综合中文88| 亚洲国产精品久久久久婷婷软件 | 日韩久久久久中文字幕人妻| 99久久亚洲综合精品成人| 2022年国产精品久久久久 | 天堂无码久久综合东京热| 国内精品免费久久影院| 中文字幕一区二区三区久久网站| 91精品国产9l久久久久| 久久九九亚洲精品| 精品国产乱码久久久久久浪潮| 国产精品一区二区久久精品无码|