• <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久久无色码中文字幕| AAA级久久久精品无码片| 国产亚州精品女人久久久久久| 久久久精品一区二区三区| 亚洲欧美一级久久精品| 中文字幕久久欲求不满| 久久亚洲精精品中文字幕| 国产日韩久久久精品影院首页| 久久午夜福利无码1000合集| 久久国产热这里只有精品| 色婷婷综合久久久久中文一区二区| 久久se精品一区二区影院| 久久99精品久久久久久hb无码| 国产精品久久久久久久久久影院| 亚洲精品tv久久久久| 国产精品亚洲美女久久久| 日韩精品久久久久久| 国产69精品久久久久99尤物| 久久www免费人成精品香蕉| 亚洲精品国产综合久久一线| 中文字幕亚洲综合久久菠萝蜜| 亚洲精品国产第一综合99久久| 99久久综合国产精品免费| 精品久久久久久国产潘金莲| 久久精品国产99久久无毒不卡| 91久久香蕉国产熟女线看| 亚洲欧美国产日韩综合久久| 久久久国产精品亚洲一区| 久久久久亚洲AV成人网人人软件| 中文字幕人妻色偷偷久久| 国产精品VIDEOSSEX久久发布| 亚洲日本va午夜中文字幕久久| 高清免费久久午夜精品| 中文字幕亚洲综合久久菠萝蜜| 秋霞久久国产精品电影院| 亚洲中文字幕无码久久精品1| 久久精品国产亚洲5555| 久久91精品国产91久久户| 91久久精一区二区三区大全|