• <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>

            哇哦~這就是我

            This is my way ~
            <2008年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統(tǒng)計(jì)

            • 隨筆 - 10
            • 文章 - 0
            • 評(píng)論 - 2
            • 引用 - 0

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            push!

            #include<iostream>
            #include<queue>
            #include<cmath>
            using namespace std;
            struct NODE
            {
             int p_x,p_y,step,c_x,c_y,d;
            };
            queue<NODE> que;
            const int MAXN = 100;
            bool p[MAXN][MAXN][4],c[MAXN][MAXN];
            int map[MAXN][MAXN];
            int mv[4][2]={-1,0,0,1,1,0,0,-1},p_sm,p_sn,c_sm,c_sn,m,n;
            void init ( )
            {
             memset(p,false,sizeof(p));
             for ( int i=0 ; i<m ; i++ )
              for ( int j=0 ; j<n ; j++ )
              {
               scanf("%d",&map[i][j]);
               if ( map[i][j]==4 )
                p_sm=i,p_sn=j;
               else
                if ( map[i][j]==2 )
                 c_sm=i,c_sn=j;
              }
            }
            int bfs ( )
            {
             NODE temp,go;
             int i;
             temp.p_x = p_sm;
             temp.p_y = p_sn;
             temp.c_x = c_sm;
             temp.c_y = c_sn;
             temp.step = 0;
             temp.d=0;
             for ( i=0 ; i<4 ; i++ )
             {
              p[p_sm][p_sn][i]=true;
              temp.d=i;
              que.push(temp);
             }
             c[c_sm][c_sn]=true;
             while ( !que.empty () )
             {
              NODE head=que.front();
              que.pop() ;
              for ( i=0 ; i<4 ; i++ )
              {
               int tm=head.p_x+mv[i][0] , tn=head.p_y+mv[i][1] ;
               if ( tm>=0 && tm<m && tn>=0 && tn<n && !p[tm][tn][i] && i!=(head.d+2)%4 && map[tm][tn]!=1 )
               {
                double t=sqrt( (double)( (tm-head.c_x)*(tm-head.c_x) ) +(double)( (tn-head.c_y)*(tn-head.c_y) ));
                if ( t <= sqrt(2.0) && t>0 )
                {
                 go=head;
                 go.p_x = tm;
                 go.p_y = tn;
                 go.step ++ ;
                 go.d=i;
                 p[tm][tn][i]=true;
                 que.push(go);
                }
                else
                {
                 int tmm=tm+mv[i][0] , tnn=tn+mv[i][1];
                 if ( t==0 && tmm>=0 && tmm<m && tnn>=0 && tnn<n && map[tmm][tnn]!=1 && !c[tmm][tnn] )
                 {
                  go.c_x = tmm ;
                  go.c_y = tnn ;
                  go.p_x = tm;
                  go.d=i;
                  go.p_y = tn;
                  go.step = head.step+1;
                  if ( map[tmm][tnn]==3 )
                   return go.step ;
                  c[tmm][tnn]=true;
                  p[tm][tn][i]=true;
                  que.push(go);
                 }
                }
               }
              }
             }
             return -1;
            }
            int main ( )
            {
             while ( scanf("%d%d",&n,&m)!=EOF )
             {
              init();
              printf("%d\n",bfs());
             // que.

             }
            }

            posted on 2008-05-28 01:36 chinaeli 閱讀(201) 評(píng)論(0)  編輯 收藏 引用


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


            久久本道久久综合伊人| 精品欧美一区二区三区久久久| 国产精品VIDEOSSEX久久发布| 青青热久久国产久精品 | 色婷婷久久久SWAG精品| 久久人妻少妇嫩草AV无码蜜桃| 伊人久久久AV老熟妇色| 久久久久免费看成人影片| A级毛片无码久久精品免费| 热久久最新网站获取| 欧美久久综合性欧美| 久久久久亚洲精品日久生情| 国产日韩久久久精品影院首页| 人妻少妇精品久久| 久久99国产精品99久久| av无码久久久久不卡免费网站| 国产精品久久久久久久久久影院| 精品国产91久久久久久久a | 99久久人妻无码精品系列| 精品99久久aaa一级毛片| 国产精品美女久久久m| 亚洲精品国精品久久99热一| 77777亚洲午夜久久多人| 久久人人爽人人精品视频| 久久综合综合久久狠狠狠97色88| 精品国产乱码久久久久软件| 久久久久亚洲AV成人网人人软件| 97r久久精品国产99国产精| 91久久精一区二区三区大全| 久久99精品久久久大学生| 久久久噜噜噜久久| 人妻少妇精品久久| 久久伊人色| 亚洲美日韩Av中文字幕无码久久久妻妇| 国产精久久一区二区三区| 国产精品九九九久久九九| 国内精品伊人久久久久AV影院| 久久人人爽人人爽人人AV| 久久99精品国产麻豆婷婷| 国内精品久久久久久久久电影网 | 久久99热只有频精品8|