• <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>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            簡單的迭代加深搜索求最優解。注意判斷可以繼續行走的條件。
            以下是我的代碼:
            /*
             * Author:  lee1r
             * Created Time:  2011/8/6 8:51:53
             * File Name: poj3009.cpp
             
            */
            #include
            <iostream>
            #include
            <sstream>
            #include
            <fstream>
            #include
            <vector>
            #include
            <list>
            #include
            <deque>
            #include
            <queue>
            #include
            <stack>
            #include
            <map>
            #include
            <set>
            #include
            <bitset>
            #include
            <algorithm>
            #include
            <cstdio>
            #include
            <cstdlib>
            #include
            <cstring>
            #include
            <cctype>
            #include
            <cmath>
            #include
            <ctime>
            #define L(x) ((x)<<1)
            #define R(x) (((x)<<1)+1)
            #define Half(x) ((x)>>1)
            #define lowbit(x) ((x)&(-(x)))
            using namespace std;
            const int kInf(0x7f7f7f7f);
            const double kEps(1e-8);
            typedef 
            long long int64;
            typedef unsigned 
            long long uint64;

            const int kMaxn(27);
            const int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

            int n,m,s1,s2,g1,g2,r[kMaxn][kMaxn];
            bool success;

            int Check(int x,int y,int dir,int &xx,int &yy)
            {
                
            int t(0);
                
            do
                {
                    
            if(r[x][y]==3)
                    {
                        xx
            =x;
                        yy
            =y;
                        
            return 3;
                    }
                    
            else if(t<=1 && r[x][y]==1)
                        
            return 0;
                    
            else if(t>1 && r[x][y]==1)
                    {
                        xx
            =x;
                        yy
            =y;
                        
            return 1;
                    }
                    x
            +=dx[dir];
                    y
            +=dy[dir];
                    t
            ++;
                }
            while(x>=1 && x<=&& y>=1 && y<=m);
                
            return 0;
            }

            void dfs(int depth,int x,int y,int maxdepth)
            {
                
            if(depth>maxdepth)
                {
                    
            if(g1==&& g2==y)
                        success
            =true;
                    
            return;
                }
                
            for(int i=0;i<4;i++)
                {
                    
            int newx,newy,result(Check(x,y,i,newx,newy));
                    
            if(result==1)
                    {
                        r[newx][newy]
            =0;
                        dfs(depth
            +1,newx-dx[i],newy-dy[i],maxdepth);
                        r[newx][newy]
            =1;
                    }
                    
            else if(result==3)
                        dfs(depth
            +1,newx,newy,maxdepth);
                }
            }

            int main()
            {
                
            //freopen("data.in","r",stdin);
                
                
            while(scanf("%d%d",&m,&n)==2 && (n || m))
                {
                    
            for(int i=1;i<=n;i++)
                        
            for(int j=1;j<=m;j++)
                        {
                            scanf(
            "%d",&r[i][j]);
                            
            if(r[i][j]==2)
                            {
                                s1
            =i;s2=j;
                            }
                            
            else if(r[i][j]==3)
                            {
                                g1
            =i;g2=j;
                            }
                        }
                    
                    
            int ans;
                    success
            =false;
                    
            for(ans=1;ans<=10;ans++)
                    {
                        dfs(
            1,s1,s2,ans);
                        
            if(success)
                            
            break;
                    }
                    
                    
            if(ans>10)
                        printf(
            "%d\n",-1);
                    
            else
                        printf(
            "%d\n",ans);
                }
                
                
            return 0;
            }
            posted on 2011-08-06 09:34 lee1r 閱讀(334) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:搜索
            国产精品视频久久久| 久久无码专区国产精品发布| 久久久一本精品99久久精品88| 久久人人爽人人爽人人AV| 久久av无码专区亚洲av桃花岛| 久久99国产精品久久| 久久乐国产综合亚洲精品| 久久精品国产亚洲av影院| 久久婷婷五月综合色99啪ak| 久久精品卫校国产小美女| 一本久久a久久精品综合夜夜 | 久久久久成人精品无码中文字幕 | 久久婷婷人人澡人人| 色欲综合久久中文字幕网| 国产精品va久久久久久久| 午夜精品久久久久久久久| 国内精品久久久久久久涩爱| 久久综合综合久久综合| 久久综合一区二区无码| 久久91精品国产91久久麻豆| 国产精品久久久久a影院| 久久综合狠狠综合久久激情 | 久久九九久精品国产| 亚洲AV日韩精品久久久久久| 久久www免费人成看国产片| 久久91精品国产91久久小草| 久久久久亚洲av无码专区导航 | 久久亚洲中文字幕精品一区| 99精品久久久久久久婷婷| 国产成人精品久久一区二区三区| 久久人人爽人人爽人人片AV麻烦 | 精品久久久久久久久久久久久久久| 伊人色综合久久天天人手人婷| 久久人人爽人人爽人人片AV东京热| 久久最新精品国产| 久久99精品久久久久久久不卡| 日韩人妻无码精品久久久不卡| 国内精品久久久久影院老司| 国内精品伊人久久久影院| 亚洲精品蜜桃久久久久久| 久久狠狠高潮亚洲精品|