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

            遞歸的非遞歸寫(xiě)法

            #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 閱讀(643) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            導(dǎo)航

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久国产福利免费| 精品视频久久久久| 久久综合给合久久狠狠狠97色| 久久精品国产亚洲av麻豆蜜芽 | 久久久久一区二区三区| 亚洲一区二区三区日本久久九| 韩国无遮挡三级久久| 久久噜噜久久久精品66| 久久这里的只有是精品23| 久久久女人与动物群交毛片| 精品午夜久久福利大片| 免费精品久久久久久中文字幕| 亚洲精品无码成人片久久| 久久免费高清视频| 亚洲中文字幕无码久久综合网| 久久精品国产福利国产秒| 久久人人爽人人爽人人片AV东京热 | 99热成人精品免费久久| 国产成人无码精品久久久性色| 久久精品国产亚洲网站| 久久久久波多野结衣高潮| 国产AⅤ精品一区二区三区久久| 久久久久亚洲AV片无码下载蜜桃| 久久免费小视频| 国产亚洲精品自在久久| 久久无码AV中文出轨人妻| 久久99热这里只有精品国产 | 久久中文字幕一区二区| 亚洲AV日韩精品久久久久久久| 日韩欧美亚洲综合久久影院Ds| 色综合久久中文综合网| 久久大香香蕉国产| 久久99精品久久久久子伦| 亚洲中文精品久久久久久不卡| 久久久久久久综合日本| 国产三级观看久久| 久久国产午夜精品一区二区三区| 97精品国产97久久久久久免费| 99久久精品国产高清一区二区| 久久99精品国产麻豆| 久久A级毛片免费观看|