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

            Ural 1033 Labyrinth

            Accepted
            0.015 217 KB

            1033. Labyrinth

            Time Limit: 1.0 second
            Memory Limit: 16 MB
            Administration of the labyrinth has decided to start a new season with new wallpapers. For this purpose they need a program to calculate the square of the walls inside the labyrinth. This job is just for you!
            The labyrinth is represented by a matrix N×N (3 ≤ N ≤ 33, you see, ‘3’ is a magic digit!). Some matrix cells contain a dot character (‘.’) that denotes an empty square. Other cells contain a diesis character (‘#’) that denotes a square filled by monolith block of stone wall. All squares are of the same size 3×3 meters.
            The walls are constructed around the labyrinth (except for the upper left and lower right corners, which are used as entrances) and on the cells with a diesis character. No other walls are constructed. There always will be a dot character at the upper left and lower right corner cells of the input matrix.
            Problem illustration
            Your task is to calculate the square of visible part of the walls inside the labyrinth. In other words, the square of the walls' surface visible to a visitor of the labyrinth. Note that there's no holes to look or to move through between any two adjacent blocks of the wall. The blocks are considered to be adjacent if they touch each other in any corner. See picture for an example: visible walls inside the labyrinth are drawn with bold lines. The height of all the walls is 3 meters.

            Input

            The first line of the input contains the single number N. The next N lines contain N characters each. Each line describes one row of the labyrinth matrix. In each line only dot and diesis characters will be used and each line will be finished with a new line character. There will be no spaces in the input.

            Output

            Your program should print to the output a single integer — the exact value of the square of the wallpaper needed.

            Sample

            input output
            5
                        .....
                        ...##
                        ..#..
                        ..###
                        .....
                        
            198
                        

            搜索題:注意的要從兩個入口處搜索,防止中間斷開了
            wa了兩次 找不出錯誤,search(i+1,j)寫成search(i+1,j+1);
            #include<iostream>
            #include
            <cstring>
            using namespace std;

            int const maxSize=35;

            class ural1033
            {
            public:
                ural1033(){ size
            =0; memset(f,0,sizeof f); }
                
            void input();
                
            void print();
                
            void search(int i, int j);
                
            int size;
                
            int getn(){return N;}
            private:
                
            char a[maxSize][maxSize];
                
            bool f[maxSize][maxSize];
                
            int N;
            };

            void ural1033::input()
            {
                 cin
            >>N;
                 
            int i,j;
                 
            for(i=1; i<=N; i++)
                    
            for(j=1; j<=N; j++)
                        cin
            >>a[i][j];
                
            for(i=2; i<=N+1; i++)a[0][i]='#';
                
            for(i=2; i<=N+1; i++)a[i][0]='#';
                
            for(i=1; i<=N-1; i++)a[N+1][i]='#';
                
            for(i=1; i<=N-1; i++)a[i][N+1]='#';

            }

            void ural1033:: search(int i, int j)
            {
                
            if(i<1||i>N||j<1||j>N||a[i][j]=='#'||f[i][j]==1)return ;
                f[i][j]
            =1;
                
            if(a[i-1][j]=='#')size++;
                   
            else search(i-1,j);
                
            if(a[i][j-1]=='#')size++;
                   
            else search(i,j-1);
                
            if(a[i][j+1]=='#')size++;
                   
            else search(i,j+1);
                
            if(a[i+1][j]=='#')size++;
                   
            else search(i+1,j);
            }

            void ural1033::print()
            {
                 
            for(int i=0; i<=N+1; i++,cout<<endl)
                 
            for(int j=0; j<=N+1; j++)
                 cout
            <<a[i][j]<<' ';
                 cout
            <<endl<<endl;
                 
                 
            for(int i=0; i<=N+1; i++,cout<<endl)
                 
            for(int j=0; j<=N+1; j++)
                 cout
            <<f[i][j]<<' ';
            }

            int main()
            {
                ural1033 ural;
                ural.input();
                
                ural.search(
            1,1);
                ural.search(ural.getn(),ural.getn());
                
                cout
            <<ural.size*9<<endl;
                
                system(
            "pause");
                
            return 0;
            }

            posted on 2010-06-24 23:02 田兵 閱讀(393) 評論(0)  編輯 收藏 引用 所屬分類: URAL

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            狠狠狠色丁香婷婷综合久久五月 | 久久精品无码一区二区app| 日本强好片久久久久久AAA| 99久久99久久久精品齐齐| 狠狠色婷婷综合天天久久丁香| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲国产精品久久久久婷婷老年| 一本大道久久a久久精品综合| 久久久久国产亚洲AV麻豆| 无码日韩人妻精品久久蜜桃 | 国产日韩欧美久久| 久久SE精品一区二区| 精品久久久久久无码中文字幕一区| 97超级碰碰碰碰久久久久| 亚洲欧美伊人久久综合一区二区| 国产成人综合久久久久久| 欧美丰满熟妇BBB久久久| 91精品国产综合久久四虎久久无码一级 | 久久久久亚洲Av无码专| 久久嫩草影院免费看夜色| 久久精品国产亚洲AV无码偷窥| 精品午夜久久福利大片| 丁香色欲久久久久久综合网| 久久久久国色AV免费看图片| 欧美熟妇另类久久久久久不卡 | 久久嫩草影院免费看夜色| 国产精品久久免费| 久久亚洲精品人成综合网| 精品久久久久久无码不卡| 久久毛片免费看一区二区三区| 日本久久久久久中文字幕| 国产精品福利一区二区久久| 久久久精品人妻一区二区三区蜜桃| 综合久久一区二区三区 | 国产午夜福利精品久久| 丰满少妇人妻久久久久久| 欧洲人妻丰满av无码久久不卡| 久久综合亚洲鲁鲁五月天| 久久妇女高潮几次MBA| 97精品依人久久久大香线蕉97| 奇米影视7777久久精品人人爽|