• <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)  編輯 收藏 引用 所屬分類: 題目分類:搜索
            精品多毛少妇人妻AV免费久久| 精品久久久久久国产潘金莲| 久久伊人中文无码| av色综合久久天堂av色综合在 | 久久国产美女免费观看精品| 久久精品亚洲欧美日韩久久| 久久这里只有精品18| 精品久久久久久无码人妻蜜桃| 久久无码国产专区精品| 国产亚州精品女人久久久久久| 色婷婷综合久久久久中文| 久久天天躁狠狠躁夜夜不卡| 97久久久精品综合88久久| 久久这里都是精品| 婷婷久久精品国产| 超级碰久久免费公开视频| 99久久免费国产精品热| 午夜欧美精品久久久久久久 | 久久人人妻人人爽人人爽| 久久人人超碰精品CAOPOREN| 日本三级久久网| 久久综合九色综合精品| 国内精品人妻无码久久久影院| 99久久精品免费看国产一区二区三区| 久久人妻少妇嫩草AV蜜桃| 久久996热精品xxxx| 色综合久久最新中文字幕| 精品午夜久久福利大片| 国产精品美女久久久久网| 91精品国产综合久久婷婷| 久久久久久国产精品免费无码| 99久久国产综合精品女同图片| 久久中文字幕人妻熟av女| 亚洲中文字幕无码久久2020| 亚洲中文字幕无码一久久区| 麻豆AV一区二区三区久久| 久久亚洲AV成人无码国产| 99久久国产综合精品麻豆| 国内精品久久久久| 91久久精品视频| 亚洲精品无码久久久|