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

            poj 1101

            //======================================

            這道題大多數(shù)人都用的是廣搜
            +優(yōu)先隊列,不過我的做法是深搜

            做起來還不是很繁瑣,不過最讓人詫異的就是我原來把數(shù)組開到了

            77 ,因為w,h最大值是75加上兩行外圍空地,最大開到77就可以了啊

            但是結(jié)果卻是一直WA,困擾我很長時間,后來改到數(shù)組開到了100

            ok ac.,覺得很怪異,然后把數(shù)組開到78還是可以ac的,發(fā)出來

            供路過的acmer指點迷津。。。

            //======================================

            #include 
            <iostream>
            #include 
            <string>
            #define MAXN 78
            #define min _min
            #define inf 123456789
            using namespace std;

            char _m[MAXN][MAXN];
            bool mark[MAXN][MAXN];
            int dp[MAXN][MAXN];
            int dis[4][2= {0,1,0,-1,1,0,-1,0};
            int dis_mark[4= {4,3,2,1};
            int min;
            int x_2;
            int y_2;
            int real_w;
            int real_h;
            void dfs(int x,int y,int dir,int step);
            int main()
            {
            freopen(
            "acm.acm","r",stdin);
            // freopen("out.txt","w",stdout);
            int w;
            int h;
            int i;
            int j;
            int x_1;
            int y_1;
            int temp_x;
            int temp_y;
            string s;
            int time = 0;
            while(cin>>w>>h,w||h)
            {
               cout
            <<"Board #"<<++ time<<":"<<endl;
               getchar();
               
            int time_in = 0;
               real_w 
            = w+2;
               real_h 
            = h+2;
               memset(_m,
            ' ',sizeof(_m));
               
            for(i = 1; i <= h; ++ i)
               {
                getline(cin,s);
                
            for(j = 1; j <= w; ++ j)
                {
                 _m[i][j] 
            = s[j-1];
                }
               }

              
               
            while(cin>>y_1>>x_1>>y_2>>x_2,x_1||y_1||x_2||y_2)
               {
               
                cout
            <<"Pair "<<++ time_in<<"";
                memset(mark,
            false,sizeof(mark));
                
            for(i = 0; i < MAXN; ++ i)
                {
                 
            for(j = 0; j < MAXN; ++ j)
                 {
                  dp[i][j] 
            = inf;
                 }
                }
                min 
            = inf;
                
            for(i = 0; i < 4++ i)
                {
                 temp_x 
            = x_1 + dis[i][0];
                 temp_y 
            = y_1 + dis[i][1];
                 
            if((_m[temp_x][temp_y] != 'X' ||_m[temp_x][temp_y] == 'X' && temp_x == x_2 && temp_y == y_2) && !mark[temp_x][temp_y])
                 {
                  mark[temp_x][temp_y] 
            = true;
                  dfs(temp_x,temp_y,dis_mark[i],
            1);
               
                  mark[temp_x][temp_y] 
            = false;
                 }
                }
                
            if(min == inf)
                {
                 cout
            <<"impossible."<<endl;
                }
                
            else
                {
                 cout
            <<min;
                 cout
            <<" segments."<<endl;
                }
               }
               cout
            <<endl;
            }
            }

            void dfs(int x,int y,int dir,int step)
            {
            if(x == x_2 && y == y_2)
            {
               
            if(step < min)
               {
                min 
            = step;
               }
               
            return;
            }

            if(step < dp[x][y])
            {
               dp[x][y] 
            = step;
            }
            else
            {
               
            return;
            }

            int i;
            int j;
            int temp_x;
            int temp_y;// 右
            for(i = 0; i < 4++ i)
            {
               temp_x 
            = dis[i][0+ x;
               temp_y 
            = dis[i][1+ y;
               
            if(temp_x >= 0 && temp_x < real_h && temp_y >= 0 && temp_y <= real_w &&( _m[temp_x][temp_y] != 'X' || _m[temp_x][temp_y] == 'X' && temp_x == x_2 && temp_y == y_2)&& !mark[temp_x][temp_y])
               {
                mark[temp_x][temp_y] 
            = true;
                
            if(dis_mark[i] != dir)
                {
                 dfs(temp_x,temp_y,dis_mark[i],step
            +1);
                 
            if(step+1 < dp[temp_x][temp_y])
                  dp[temp_x][temp_y] 
            = step+1;
                }
                
            else
                {
                 dfs(temp_x,temp_y,dis_mark[i],step);
                 
            if(step < dp[temp_x][temp_y])
                  dp[temp_x][temp_y] 
            = step;
                }
                mark[temp_x][temp_y] 
            = false;
               }
            }

            }

            posted on 2010-06-19 17:00 成大才子 閱讀(697) 評論(2)  編輯 收藏 引用

            評論

            # re: poj 1101 2010-09-14 15:43 rayafjyblue

            數(shù)組開78大概是因為字符串?dāng)?shù)組的每一行都有個‘\0’吧,所以要大一點。。。。。偶也是菜鳥。。。。  回復(fù)  更多評論   

            # re: poj 1101 2010-09-25 09:08 caizi

            @rayafjyblue
            呵呵,好像不是那個原因。  回復(fù)  更多評論   


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


            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計

            公告

            關(guān)于更多關(guān)于成大才子,請訪問http://hi.baidu.com/成大才子

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章分類

            文章檔案

            鏈接

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            狠狠色综合网站久久久久久久| 久久综合欧美成人| 亚洲欧美一级久久精品| 国内精品久久久久久久涩爱| 乱亲女H秽乱长久久久| 99热成人精品热久久669| 久久久久久毛片免费播放| 久久久久久久久无码精品亚洲日韩| 奇米影视7777久久精品人人爽| 思思久久好好热精品国产| 天天综合久久一二三区| 婷婷久久香蕉五月综合加勒比| 久久精品国产免费| 国内精品久久久久影院亚洲| 日产精品久久久久久久性色| 欧美伊香蕉久久综合类网站| 国内精品伊人久久久久妇| 日本免费一区二区久久人人澡| 热久久视久久精品18| 久久久久久国产a免费观看不卡| 精品综合久久久久久97| 成人资源影音先锋久久资源网| 欧美日韩精品久久久久| 青青国产成人久久91网| 久久久久国产精品| 人人狠狠综合久久88成人| 久久久久久免费视频| 久久亚洲国产精品五月天婷| 国内精品久久久久久久影视麻豆| 热久久这里只有精品| 亚洲综合精品香蕉久久网97 | 亚洲AV无码久久精品蜜桃| 国产一区二区精品久久岳| 99久久精品国产免看国产一区| 久久久久亚洲av无码专区喷水| 777午夜精品久久av蜜臀| 久久亚洲精品国产精品| 麻豆久久| 91久久精品视频| 亚洲人成无码www久久久| 久久不见久久见免费视频7|