• <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 閱讀(323) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:搜索
            理论片午午伦夜理片久久 | 精品久久久久久成人AV| 天天躁日日躁狠狠久久| 波多野结衣中文字幕久久| 精品久久777| 免费精品国产日韩热久久| 亚洲va久久久噜噜噜久久| 久久精品99无色码中文字幕| 麻豆av久久av盛宴av| 嫩草影院久久99| 三上悠亚久久精品| 精品国产乱码久久久久久浪潮| 欧美日韩精品久久免费| 久久精品9988| 久久亚洲中文字幕精品有坂深雪| 久久精品一区二区三区中文字幕| 久久久久久伊人高潮影院| 精品国产青草久久久久福利| 久久亚洲精品中文字幕| 亚洲欧洲久久久精品| 99久久无色码中文字幕| 77777亚洲午夜久久多喷| 久久有码中文字幕| 久久精品成人免费观看97| 狠狠色丁香婷综合久久| 久久成人国产精品| 亚洲精品tv久久久久久久久| 久久无码精品一区二区三区| 99久久综合国产精品二区| 国内精品久久人妻互换| 亚洲色婷婷综合久久| 久久久精品国产| 一本色道久久88综合日韩精品 | 一本一道久久a久久精品综合| 狠狠色伊人久久精品综合网| 久久se精品一区精品二区| 国产精品久久成人影院| 久久久久一区二区三区| 久久精品夜色噜噜亚洲A∨| 久久影院午夜理论片无码| 综合久久一区二区三区|