• <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 閱讀(645) 評論(0)  編輯 收藏 引用


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


            導(dǎo)航

            <2008年1月>
            303112345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            一本综合久久国产二区| 伊人久久大香线蕉综合Av | 伊人久久大香线蕉精品不卡 | 国产成人久久激情91| 久久综合久久久| 亚洲天堂久久久| 伊人久久久AV老熟妇色| 国产精品美女久久久久av爽| 亚洲一区精品伊人久久伊人| 久久精品99久久香蕉国产色戒| 国产高清国内精品福利99久久| 99久久夜色精品国产网站| 四虎国产精品免费久久久| 欧美精品九九99久久在观看| 国产成人综合久久综合| 少妇高潮惨叫久久久久久| 久久伊人亚洲AV无码网站| 国产精品久久久久…| 亚洲天堂久久久| 久久久久综合中文字幕| 久久r热这里有精品视频| 久久亚洲精品成人无码网站| 国产精品激情综合久久| 国产∨亚洲V天堂无码久久久| 欧美日韩精品久久久免费观看| 国产精品无码久久久久| 青青草国产精品久久久久| 99久久99这里只有免费费精品 | 久久久精品视频免费观看| 国产午夜久久影院| 久久99国产综合精品女同| 久久国产精品一国产精品金尊| 久久精品国产色蜜蜜麻豆| 伊人久久精品影院| 亚洲美日韩Av中文字幕无码久久久妻妇 | 国产成人精品综合久久久久| 久久久久18| 国产免费久久精品99re丫y| 中文字幕无码久久人妻| 伊人伊成久久人综合网777| 模特私拍国产精品久久|