• <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)  編輯 收藏 引用

            導航

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

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            2020久久精品亚洲热综合一本| 亚洲精品无码专区久久同性男| 欧美久久久久久| 亚洲精品国产美女久久久| 日本人妻丰满熟妇久久久久久| 一级做a爱片久久毛片| 日韩精品久久久久久久电影| 亚洲精品国产美女久久久| 91麻精品国产91久久久久| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 999久久久无码国产精品| 香蕉久久一区二区不卡无毒影院| 精品久久久久中文字| 国产婷婷成人久久Av免费高清 | 99久久99久久| 18禁黄久久久AAA片| 99久久99久久精品国产| 无码AV波多野结衣久久| 无码任你躁久久久久久久| 国产精品内射久久久久欢欢| 久久精品人人做人人妻人人玩| 久久精品国产免费观看| 久久精品国产2020| 亚洲国产成人久久综合野外| 久久免费小视频| 久久综合九色综合久99| 亚洲国产成人久久综合碰| 久久国产一区二区| 久久夜色精品国产www| 久久精品国产亚洲网站| av无码久久久久不卡免费网站| 中文字幕热久久久久久久| 久久午夜羞羞影院免费观看| 无码人妻少妇久久中文字幕| 欧美性大战久久久久久| 久久精品无码一区二区三区日韩 | 亚洲国产精品狼友中文久久久| 亚洲国产精品久久久久网站| 久久国产亚洲精品麻豆| 久久免费国产精品一区二区| 国产精品九九久久精品女同亚洲欧美日韩综合区 |