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

            comiz

            a problem of maze

            Problem Statement

            People enjoy mazes, but they also get them dirty. Arrows, graffiti, and chewing gum are just a few of the souvenirs people leave on the walls. You, the maze keeper, are assigned to whiten the maze walls. Each face of the wall requires one liter of paint, but you are only required to paint visible faces. You are given a map of the maze, and you must determine the amount of paint needed for the job.

            The maze is described by a vector <string> maze, where each character can be either '#' (a wall) or '.' (an empty space). All '.' characters on the perimeter of the map are considered entrances to the maze. Upon entering the maze, one can only move horizontally and vertically through empty spaces, and areas that are not reachable by these movements are not considered visible. Each '#' represents a square block with four wall faces (each side of the square is a face). A face is visible if it is not directly adjacent to another wall (and is in a reachable area of the maze). For example, two adjacent blocks can have at most six visible faces since two of their faces are directly adjacent to each other. All exterior faces on the perimeter are considered visible.

            For example, the following picture represents a trivial maze with just one (wide) entrance and only four empty reachable spaces:

             TroytownKeeper.png

            To whiten this maze you must paint the faces highlighted in yellow above: 16 for its perimeter, plus 8 interior faces. Note that there are faces that are not visible and thus need not be painted.

            Definition     

            Class: TroytownKeeper

            Method: limeLiters Parameters: vector <string>

            Returns: int

            Method signature: int limeLiters(vector <string> maze)

            (be sure your method is public)     

            Constraints

            - maze will contain between 1 and 50 elements, inclusive.

            - Each element of maze will contain between 1 and 50 characters, inclusive.

            - All elements of maze will have the same number of characters.

            - All characters in maze will be either '.' or '#' . Examples 0)  

             

               

            {"##..#",
            "#.#.#",
            "#.#.#",
            "#####"}
            Returns: 24

            posted on 2007-11-04 19:35 comiz 閱讀(405) 評(píng)論(1)  編輯 收藏 引用

            評(píng)論

            # re: a problem of maze 2007-11-04 19:35 comiz

            using System;
            using System.Collections;
            using System.ComponentModel;
            using System.Data;
            using System.Threading;

            namespace TroytownKeeper
            {

            public class TroytownKeeper
            {
            string [] maze;
            bool [,]used=new bool[100,100];
            int sum=0;
            public TroytownKeeper()
            {



            }

            public int LimeLiters(string [] maze)
            {
            this.maze=maze;
            for(int x=0;x<maze.GetLength(0);x++)
            {
            if(maze[x][0]=='.') dfs(x,0);
            if(maze[x][maze[0].Length-1]=='.') dfs(x,maze[0].Length-1);
            }
            for(int y=0;y<maze[0].Length-1;y++)
            {
            if(maze[0][y]=='.') dfs(0,y);
            if(maze[maze.GetLength(0)-1][y]=='.') dfs(maze.GetLength(0)-1,y);
            }

            for(int x=0;x<maze.GetLength(0);x++)
            for(int y=0;y<maze[0].Length;y++)
            if(maze[x][y]=='#')
            {
            //upside
            if(x==0)
            sum++;
            if(x<maze.Length-1&&used[x+1,y])
            sum++;
            //leftside
            if(y==0)
            sum++;
            if(y>0&&used[x,y-1])
            sum++;
            //underside
            if(x==maze.Length-1)
            sum++;
            if(x>0&&used[x-1,y])
            sum++;
            //rightside
            if(y==maze[0].Length-1)
            sum++;
            if(y<maze[0].Length-1&&used[x,y+1])
            sum++;
            }
            return sum;
            }

            static void Main(string[] args)
            {
            TroytownKeeper TK=new TroytownKeeper();
            string [] str={"##..#"
            ,"#.#.#"
            ,"#.#.#"
            ,"#####"};
            int count=TK.LimeLiters(str);
            Console.WriteLine(count.ToString());
            }


            void dfs(int x,int y)
            {
            used[x,y]=true;
            if(x<maze.GetLength(0)&&maze[x+1][y]=='.'&&!used[x+1,y]) dfs(x+1,y);
            if(y<maze[0].Length&&maze[x][y+1]=='.'&&!used[x,y+1]) dfs(x,y+1);
            if(x>0&&maze[x-1][y]=='.'&&!used[x-1,y]) dfs(x-1,y);
            if(y>0&&maze[x][y-1]=='.'&&!used[x,y-1]) dfs(x,y-1);
            }
            }
            }

              回復(fù)  更多評(píng)論   


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


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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久香蕉超碰97国产精品| 国内精品久久久久影院老司| 免费国产99久久久香蕉| 国产成人久久777777| 亚洲国产成人久久一区WWW| 人妻少妇久久中文字幕| 国产亚州精品女人久久久久久| 亚洲国产精品无码久久青草| 奇米综合四色77777久久| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久久久无码精品| 亚洲国产另类久久久精品小说 | 欧美日韩精品久久久久| 久久精品一区二区| 久久亚洲AV无码精品色午夜 | 嫩草影院久久国产精品| 久久香综合精品久久伊人| 国产 亚洲 欧美 另类 久久| 久久久久久亚洲Av无码精品专口| 久久婷婷色综合一区二区| 97久久精品无码一区二区| 波多野结衣久久一区二区| 久久久精品日本一区二区三区 | 久久精品国产亚洲沈樵| 亚洲精品高清国产一线久久| 2020国产成人久久精品| 亚洲午夜福利精品久久| 久久精品国产亚洲Aⅴ香蕉| 7国产欧美日韩综合天堂中文久久久久 | 久久人妻少妇嫩草AV蜜桃| 四虎亚洲国产成人久久精品| 国产免费久久精品99久久| 精品精品国产自在久久高清| 久久久久99精品成人片直播| 久久国产精品99精品国产| 久久人人爽人人爽人人片AV不| 99精品久久精品一区二区| 久久久久久精品成人免费图片| 久久午夜无码鲁丝片秋霞 | 亚洲国产精品嫩草影院久久| 久久精品无码一区二区日韩AV |