青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

TC-SRM-233-1000pt BFS

Posted on 2009-11-25 11:39 rikisand 閱讀(292) 評論(0)  編輯 收藏 引用 所屬分類: TopcoderAlgorithm
繼續是misof 數字教學里面的習題~ 第一篇的最后一道題了~
Problem Statement

You are in a maze containing revolving doors. The doors can be turned 90 degrees by pushing against them in either direction. You are to find a route from the start square to the end square that involves revolving as few doors as possible. Given a map of the maze, determine the fewest number of door revolutions necessary to get from the start to the end.

In the map:

   ' ': empty space
   '#': wall
   'O': center of a revolving door (letter "oh", not zero)
   '-': horizontal door (always adjacent to a 'O')
   '|': vertical door (always adjacent to a 'O')
   'S': start square
   'E': end square

Each revolving door will always be oriented horizontally (with two horizontal segments) or vertically (with two vertical segments):

    |
    O  or  -O-
    |

Doors can be revolved 90 degrees by moving onto a door segment from any of the 4 squares diagonally adjacent to the door center, i.e., the 'X' characters below:

   X|X     X X
    O  or  -O-
   X|X     X X

Here is an example map:

        ###
        #E#
       ## #
    ####  ##
    # S -O-#
    # ###  #
    #      #
    ########

In this example, 2 door revolutions are necessary to get from 'S' to 'E'. The first turn is shown here:

        ###         ###
        #E#         #E#
       ## #        ## #
    ####  ##    #### |##
    # S -O-#    # S  OX#
    # ### X#    # ###| #
    #      #    #      #
    ########    ########

And the second turn is shown here:

        ###         ###
        #E#         #E#
       ## #        ## #
    ####X|##    #### X##
    # S  O #    # S -O-#
    # ###| #    # ###  #
    #      #    #      #
    ########    ########

Your method should return an int, the minimum number of door revolutions necessary to get from the start square to the end square. If there is no way to reach the end square, return -1.

Definition

Class:
RevolvingDoors

Method:
turns

Parameters:
vector <string>

Returns:
int

Method signature:
int turns(vector <string> map)

(be sure your method is public)

Notes

-
Assume that all squares off the edge of the map are walls.

Constraints

-
map will contain between 3 and 50 elements, inclusive.

-
Each element of map will contain between 3 and 50 characters, inclusive.

-
Each element of map will contain the same number of characters.

-
Each character in map will be one of 'S', 'E', 'O', '-', '|', '#', and ' ' (space).

-
There will be exactly one 'S' and one 'E' in map.

-
There will be between 1 and 10 doors, inclusive, and they will be formatted in map as described in the problem statement.

-
No two doors will be close enough for any part of them to occupy the same square.

-
It is not allowed for a door to be blocked and unable to turn. There will not be any walls in any of the 4 squares immediately adjacent to the center of a door, nor will a door be on the edge of the map.

關鍵是門的狀態表示,參考了網站上的代碼,挑了一個比較簡練的,用的優先級隊列。寫完調好發現TLE 囧~ copy出網站上的再run依然TLE``` ``` 看了下發現現在的system testing 比原來增加了幾個測試用例~~~   于是找出misof大牛的解法,發現對狀態處理一樣的~~~只不過用了memo和deque,省去了優先級隊列調整的時間開銷,改好了就pass了~ 上代碼~~:
Code Snippet
using namespace std;
typedef long long int64;  
typedef vector<int> VI;
typedef vector<string> VS;
#define inf 1000000
#define REP(i,n) for(int (i)=(0);((i)<(n));++(i))
template<class T> inline void checkmin(T &a,const T &b) { if (b<a) a=b; }
template<class T> inline void checkmax(T &a,const T &b) { if (b>a) a=b; }
int dr[]={-1,0,1,0};
int dc[]={0,1,0,-1};
struct state{state(int x,int y,int z,int s):r(x),c(y),doorstate(z),best(s){}int r;int c;int doorstate;int best;};
int memo[56][56][1<<11];
class RevolvingDoors
{
        public:
        int turns(vector <string> mp)
        {
             int x=mp.size()+2;int y=mp[0].size()+2;
             int sr,sc,er,ec,cnt=0,doorInit=0;
             REP(i,x-2)mp[i]='#'+mp[i]+'#';                //trick:modify the pattern to make it easy to loop
             mp.insert(mp.begin(),string(58,'#'));
             mp.push_back(string(58,'#'));
             REP(i,x)REP(j,y)if(mp[i][j]=='S'){mp[i][j]=' ';sr=i;sc=j;}else if(mp[i][j]=='E'){mp[i][j]=' ';er=i;ec=j;}
             REP(i,x)REP(j,y)if(mp[i][j]=='O'){if(mp[i-1][j]=='|')doorInit|=(1<<cnt);
                mp[i-1][j]=mp[i+1][j] = 100 + cnt*2 +1;    //use the content in the box to identify the door number,and the door pos
                mp[i][j-1]=mp[i][j+1] = 100 + cnt*2 ;    //if pos==0 it means this box is on the left or right of the door
                cnt++; mp[i][j]='#';
             }
             REP(i,x)REP(j,y)REP(t,1<<cnt) memo[i][j][t] = inf;    //init the memo
             deque<state> Q; Q.push_back(state(sr,sc,doorInit,0));
             while(!Q.empty()){
                state now=Q.front();Q.pop_front();
                int r=now.r  , c=now.c  , door=now.doorstate , b=now.best;
                if( memo[r][c][door] < b)continue;    //no better ,no vist
                REP(dir,4){                            //try four direction
                    int nr=r+dr[dir],nc=c+dc[dir];
                    if(mp[nr][nc]==' '){
                        if(memo[nr][nc][door] > b){ memo[nr][nc][door]=b;Q.push_back(state(nr,nc,door,b));}
                    }
                    else if(mp[nr][nc]=='#')continue;
                    else{                            //if we come to a box near to the door-mid
                        int doornum=(mp[nr][nc]-100)/2;int open=(mp[nr][nc]-100)%2;    
                        if( ((door>>doornum)&1) != open){    //lucily,the box is empty
                            if(memo[nr][nc][door] > b){memo[nr][nc][door] = b;Q.push_back(state(nr,nc,door,b));}
                        }        
                        else {                                // the box has a door
                            if(open==0 && dr[dir]==0) continue;    //try to define the relative pos between the direction and the box
                            if(open==1 && dc[dir]==0) continue;    //also ~ if we cannot push the door we give up
                            int ndoor=door^(1<<doornum);    //we can go into the box if we push the door ~
                            if(memo[nr][nc][ndoor] > b+1 ){memo[nr][nc][ndoor] = b+1 ;Q.push_back(state(nr,nc,ndoor,b+1));}
                        }
                    }
                }
             }
             int ans=inf;
             REP(i,1<<cnt){ //loop to check the best ans~
                 if(memo[er][ec][i]<ans){ans=memo[er][ec][i];cout<<er<<" "<<ec<<" "<<hex<<i<<endl;}
             }
             if(ans == inf) return -1;
             else return ans;
        }

中文copy是亂碼···囧啊~~ 俺的破爛英文注釋啊~~~

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美激情综合网| 91久久精品久久国产性色也91| 亚洲九九九在线观看| 久久亚洲春色中文字幕| 销魂美女一区二区三区视频在线| 一区二区三区视频观看| 亚洲欧美激情精品一区二区| 午夜精品久久久久久99热软件 | 亚洲性xxxx| 亚洲欧美视频| 久久久999精品| 欧美激情bt| 国产精品久久久久久久久久三级| 国产精品美女| 国产在线一区二区三区四区| 在线观看一区二区视频| 亚洲东热激情| 亚洲性视频网址| 巨胸喷奶水www久久久免费动漫| 欧美99在线视频观看| 日韩一区二区久久| 欧美中文在线视频| 欧美裸体一区二区三区| 国产精品日日摸夜夜摸av| 伊人夜夜躁av伊人久久| 亚洲天堂成人在线观看| 久久久另类综合| 99精品久久免费看蜜臀剧情介绍| 欧美在线999| 欧美福利专区| 国产综合欧美| 亚洲欧美国产日韩天堂区| 老牛嫩草一区二区三区日本| 一本色道精品久久一区二区三区 | 欧美精品久久久久久久| 国产亚洲欧洲一区高清在线观看| 亚洲三级影院| 亚洲国产精品成人一区二区| 亚洲黄页一区| 一区二区三区国产在线观看| 久久精品av麻豆的观看方式| 欧美香蕉视频| 一区二区av在线| 欧美激情精品久久久六区热门| 国产精品99久久久久久宅男| 欧美成人精品一区| 国产综合欧美在线看| 亚洲少妇最新在线视频| 欧美激情亚洲另类| 亚洲精品综合在线| 久久久国产成人精品| 中文欧美字幕免费| 欧美精品一区二区三区一线天视频 | 亚洲午夜视频在线观看| 欧美精品二区| 日韩午夜电影| 亚洲国产日日夜夜| 老妇喷水一区二区三区| 激情六月婷婷久久| 久久频这里精品99香蕉| 欧美在线播放视频| 国内精品美女在线观看| 久久精品99无色码中文字幕| 亚洲自拍都市欧美小说| 国产精品亚洲欧美| 午夜精品美女久久久久av福利| 亚洲午夜精品久久久久久浪潮 | 99视频一区二区| 欧美三日本三级少妇三99| 中文在线不卡| 中文亚洲免费| 国产亚洲精品aa午夜观看| 欧美一区在线直播| 久久精品123| 亚洲人成网站在线观看播放| 亚洲精品免费在线播放| 欧美日韩精品久久久| 亚洲午夜在线| 午夜视频久久久| 一区二区三区我不卡| 亚洲大黄网站| 欧美视频日韩| 久久精品九九| 欧美大胆人体视频| 亚洲一区亚洲| 欧美一区=区| 91久久精品www人人做人人爽 | 久久九九国产| 美女诱惑黄网站一区| 一本一本大道香蕉久在线精品| 国产亚洲成年网址在线观看| 亚洲中字在线| 久久一二三国产| 一区精品在线播放| 免费欧美电影| 极品尤物av久久免费看| 蜜桃久久av| 亚洲欧美中文字幕| 亚洲国产精品一区二区www在线| 亚洲午夜激情| 亚洲国产另类 国产精品国产免费| 欧美大学生性色视频| 欧美亚洲综合久久| 日韩一区二区免费看| 裸体歌舞表演一区二区| 亚洲最新在线视频| 在线播放日韩欧美| 黄色国产精品| 影音先锋亚洲视频| 狠狠做深爱婷婷久久综合一区 | 欧美国产国产综合| 久久婷婷久久一区二区三区| 性欧美video另类hd性玩具| av72成人在线| 亚洲图片欧美一区| 羞羞色国产精品| 99ri日韩精品视频| 亚洲一区二区三区四区五区午夜| 99re6这里只有精品| 亚洲精品中文字幕有码专区| 亚洲国产日韩欧美在线图片| 欧美大香线蕉线伊人久久国产精品| 久久久久这里只有精品| 亚洲第一精品福利| 亚洲视频一二| 一区二区三区精品在线 | 一本色道久久综合亚洲精品按摩| 亚洲激情视频在线播放| 一本色道久久88综合亚洲精品ⅰ| 亚洲免费观看高清完整版在线观看熊| 亚洲精品中文字幕女同| 亚洲综合电影| 欧美黄网免费在线观看| 国产一区二区三区精品欧美日韩一区二区三区 | 久久精品一区四区| 欧美精品国产精品日韩精品| 国产精品美女www爽爽爽| 国内精品久久久久国产盗摄免费观看完整版| 国产午夜亚洲精品不卡| 一本色道久久综合| 久久九九热re6这里有精品| 亚洲七七久久综合桃花剧情介绍| 一区二区精品| 欧美激情一区二区久久久| 国内精品久久久久久久果冻传媒 | 亚洲电影免费观看高清完整版在线观看 | 国产精品青草久久| 亚洲国产精品一区二区www| 午夜亚洲性色视频| 国产日韩欧美在线视频观看| 亚洲人永久免费| 国内精品伊人久久久久av一坑| 亚洲一区亚洲二区| 亚洲一区视频在线| 欧美日韩精品欧美日韩精品| 亚洲精品乱码久久久久久| 久久精品国产欧美激情| 欧美在线一区二区三区| 亚洲国产电影| 欧美激情成人在线| 久久只精品国产| 亚洲精品久久久久久久久久久久久| 欧美69视频| 欧美三区在线观看| 久久精品国产精品亚洲综合| 久久伊人精品天天| 午夜国产不卡在线观看视频| 午夜视频在线观看一区| 亚洲精品色婷婷福利天堂| 亚洲一区二区久久| 亚洲免费观看高清在线观看 | 午夜精品福利电影| 日韩一区二区精品葵司在线| 亚洲欧美日韩国产一区二区| 亚洲激情成人网| 久久国产婷婷国产香蕉| 午夜精品久久久久久久| 欧美成人精品一区二区| 欧美成人精品福利| 国产亚洲成av人片在线观看桃| avtt综合网| 亚洲欧美色一区| 国产精品毛片| 午夜精彩国产免费不卡不顿大片| 亚洲欧美福利一区二区| 亚洲美女视频| 免费亚洲电影在线| 久久久久久久激情视频| 国产精品日韩在线观看| 日韩亚洲精品在线| 一区二区三欧美| 欧美日韩亚洲高清| 国产日韩欧美亚洲一区| 亚洲视频日本| 久久久精品日韩欧美| 国产女主播一区二区| 亚洲女ⅴideoshd黑人| 亚洲免费成人| 欧美精品一区二区视频| 亚洲人精品午夜|