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

            USACO 2.4 Overfencing


            找出兩個迷宮的出口,然后分別進行dfs,求出到每一個點的最短距離。
            然后對每一個點,求到最短的那個出口的距離,然后再求這個值的最大值即可。
            找出口寫得比較繁瑣。

            #include?<iostream>
            #include?
            <fstream>
            #include?
            <queue>

            using?namespace?std;

            ifstream?fin(
            "maze1.in");
            ofstream?fout(
            "maze1.out");

            #ifdef?_DEBUG
            #define?out?cout
            #define?in?cin
            #else
            #define?out?fout
            #define?in?fin
            #endif

            char?maze[2*100+1][2*38+1];

            bool?visited[100][38];

            int?shortest1[100][38];
            int?shortest2[100][38];

            bool?get_first;
            int?exit1r,exit1c;
            int?exit2r,exit2c;
            int?w,h;

            struct?queue_node{
            ????
            int?i,j,depth;
            ????queue_node(
            int?i,int?j,int?depth){
            ????????
            this->i?=?i;
            ????????
            this->j?=?j;
            ????????
            this->depth?=?depth;
            ????}
            };

            void?bfs(int?i,int?j,int?shortest[100][38])
            {
            ????queue
            <queue_node>q;

            ????q.push(queue_node(i,j,
            1));

            ????
            while(!q.empty()){

            ????????queue_node?node?
            =?q.front();
            ????????q.pop();

            ????????
            if(visited[node.i][node.j])
            ????????????
            continue;

            ????????visited[node.i][node.j]?
            =?true;

            ????????shortest[node.i][node.j]?
            =?node.depth;

            ????????
            if(node.i!=0&&maze[2*node.i][2*node.j+1]=='?'){
            ????????????q.push(queue_node(node.i
            -1,node.j,node.depth+1));
            ????????}
            ????????
            if(node.i!=h-1&&maze[2*node.i+2][2*node.j+1]=='?'){
            ????????????q.push(queue_node(node.i
            +1,node.j,node.depth+1));
            ????????}
            ????????
            if(node.j!=0&&maze[2*node.i+1][2*node.j]=='?'){
            ????????????q.push(queue_node(node.i,node.j
            -1,node.depth+1));
            ????????}
            ????????
            if(node.j!=w-1&&maze[2*node.i+1][2*node.j+2]=='?'){
            ????????????q.push(queue_node(node.i,node.j
            +1,node.depth+1));
            ????????}
            ????}
            }

            void?solve()
            {
            ????
            in>>w>>h;

            ????
            for(int?i=0;i<2*h+1;++i)
            ????????
            for(int?j=0;j<2*w+1;++j){

            ????????????
            do{
            ????????????
            in.get(maze[i][j]);
            ????????????}
            while(maze[i][j]=='\n');

            ????????????
            if((i==0||i==2*h||j==0||j==2*w)&&maze[i][j]=='?'){
            ????????????????
            if(!get_first){
            ????????????????????
            if(i==2*h)
            ????????????????????????exit1r?
            =?h-1;
            ????????????????????
            else
            ????????????????????????exit1r?
            =?i/2;
            ????????????????????
            if(j==2*w)
            ????????????????????????exit1c?
            =?w-1;
            ????????????????????
            else
            ????????????????????????exit1c?
            =?j/2;
            ????????????????????get_first?
            =?true;
            ????????????????}
            else{
            ????????????????????
            if(i==2*h)
            ????????????????????????exit2r?
            =?h-1;
            ????????????????????
            else
            ????????????????????????exit2r?
            =?i/2;
            ????????????????????
            if(j==2*w)
            ????????????????????????exit2c?
            =?w-1;
            ????????????????????
            else
            ????????????????????????exit2c?
            =?j/2;
            ????????????????}
            ????????????}
            ????????}

            ????memset(visited,
            0,sizeof(visited));
            ????bfs(exit1r,exit1c,shortest1);
            ????memset(visited,
            0,sizeof(visited));
            ????bfs(exit2r,exit2c,shortest2);

            ????
            int?res?=?INT_MIN;

            ????
            for(int?i=0;i<h;++i)
            ?????
            for(int?j=0;j<w;++j){
            ?????????res?
            =?max(res,?min(shortest1[i][j],shortest2[i][j])?);
            ?????}

            ????
            out<<res<<endl;
            }

            int?main(int?argc,char?*argv[])
            {
            ????solve();?
            ????
            return?0;
            }



            posted on 2009-06-26 22:25 YZY 閱讀(1252) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO搜索

            導航

            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久se这里只有精品| 久久天堂AV综合合色蜜桃网| 91麻豆精品国产91久久久久久| 久久国产一区二区| 国产精品成人99久久久久 | 久久亚洲高清观看| 精品欧美一区二区三区久久久| 亚洲欧洲精品成人久久曰影片 | 午夜精品久久久内射近拍高清| 国产精品美女久久福利网站| 国产精品美女久久久久 | 久久人人爽人人人人爽AV| 久久久女人与动物群交毛片| 久久九九久精品国产| 91精品国产91久久久久福利| 麻豆国内精品久久久久久| 色综合久久久久综合体桃花网| 久久99精品久久久久久齐齐| 精品久久久久香蕉网| 久久无码中文字幕东京热| 国产激情久久久久影院老熟女| 中文字幕久久精品无码| 久久久久免费视频| 9191精品国产免费久久| 国产精品久久久久久搜索| 少妇内射兰兰久久| 久久午夜福利无码1000合集| 一本色道久久综合| 三级片免费观看久久| 久久一区二区三区99| 久久精品亚洲欧美日韩久久| 国产精品国色综合久久| 国产精品一区二区久久不卡| 久久天天躁狠狠躁夜夜网站| 婷婷久久久亚洲欧洲日产国码AV| 久久久久人妻一区二区三区| 国产精品久久久久久五月尺| 久久成人小视频| 无码超乳爆乳中文字幕久久 | 久久精品18| 国内精品久久久久影院网站|