• <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>
            posts - 33,  comments - 33,  trackbacks - 0
            大意:給出一個區域圖和Click的坐標,求擊中區域的周長
            題解:爆搜,BFS出整個連通域,注意求周長是上下左右的連通域,所以將8連域分成兩個4連域,然后在BFS時一并計算出周長
            代碼:
            #include <stdio.h>
            #include 
            <queue>
            using namespace std;

            const int dsx1[4= {1,0,-1,0};
            const int dsy1[4= {0,1,0,-1};
            const int dsx2[4= {1,-1,-1,1};
            const int dsy2[4= {1,1,-1,-1};

            int width;
            int height;
            int startX,startY;
            char Maps[25][25];
            bool visited[25][25];

            const bool bound(int _x,int _y)
            {
                
            return (_x >=0 && _x < width)&&(_y >= 0 && _y < height);
            }


            int BFS()
            {
                
            int ret = 0;
                
            if (Maps[startY][startX] !='X')
                
            {
                    
            return 0;
                }

                memset(visited,
            0,sizeof(visited));
                queue
            <int> que;
                que.push(startY
            *100 + startX);
                visited[startY][startX] 
            = true;
                
            while(!que.empty())
                
            {
                    
            int curId = que.front();
                    que.pop();
                    
            int curX = curId % 100;
                    
            int curY = curId / 100;
                    
            int newX,newY;
                    
            for (int i = 0; i < 4++i)
                    
            {
                        newX 
            = curX + dsx1[i];
                        newY 
            = curY + dsy1[i];
                        
            if (bound(newX,newY))
                        
            {
                            
            if (!visited[newY][newX])
                            
            {    
                                
            if (Maps[newY][newX] == 'X')
                                
            {
                                    visited[newY][newX] 
            = true;
                                    que.push(newY
            *100 + newX);
                                }

                                
            else
                                
            {
                                    
            //add
                                    ++ret;
                                }

                            }

                        }

                        
            else
                        
            {
                            
            ++ret;
                        }

                    }

                    
            for (int i = 0; i < 4++i)
                    
            {
                        newX 
            = curX + dsx2[i];
                        newY 
            = curY + dsy2[i];
                        
            if (bound(newX,newY))
                        
            {
                            
            if (!visited[newY][newX])
                            
            {        
                                
            if (Maps[newY][newX] == 'X')
                                
            {
                                    
                                    visited[newY][newX] 
            = true;
                                    que.push(newY
            *100 + newX);
                                }

                            }

                        }

                    }

                }

                
            return ret;
            }


            void Test()
            {
                memset(Maps,
            0,sizeof(Maps));
                
            for (int i = 0; i < height; ++i)
                
            {
                    scanf(
            "%s",Maps[i]);
                }

                printf(
            "%d\n",BFS());
            }


            int main()
            {
                
            //freopen("data.txt","r",stdin);
                while(scanf("%d %d %d %d",&height,&width,&startY,&startX) != EOF)
                
            {
                    
            if (height == 0)
                    
            {
                        
            break;
                    }

                    
            --startY;
                    
            --startX;
                    Test();
                }

                
            return 0;
            }


            posted on 2011-11-09 12:34 bennycen 閱讀(1528) 評論(1)  編輯 收藏 引用 所屬分類: 算法題解
            久久久久国产精品人妻| 精品久久久噜噜噜久久久| 久久精品视频一| 久久久无码一区二区三区| 国产精品视频久久久| 精品熟女少妇aⅴ免费久久| 一本一本久久A久久综合精品| 97r久久精品国产99国产精| 色偷偷88欧美精品久久久| 亚洲AV无码久久精品色欲| 久久电影网| 国产精品久久久天天影视| 国内精品久久久久影院亚洲| 色综合久久久久网| 国产V综合V亚洲欧美久久| 久久久久青草线蕉综合超碰| 国产99久久久久久免费看| 国产精品无码久久久久久| 久久人妻AV中文字幕| 欧美久久亚洲精品| 久久精品这里只有精99品| 伊人久久综合热线大杳蕉下载| 97久久婷婷五月综合色d啪蜜芽| 久久亚洲中文字幕精品一区四| 久久电影网2021| 久久久久亚洲AV无码网站| 伊人久久精品无码av一区| 亚洲国产成人久久一区WWW| 久久亚洲欧洲国产综合| 久久久久国产日韩精品网站| 久久精品国产精品亚洲下载| 品成人欧美大片久久国产欧美| 狠狠色丁香久久综合五月| 精品国产VA久久久久久久冰| 欧美丰满熟妇BBB久久久| 日韩乱码人妻无码中文字幕久久| 中文字幕无码免费久久| 国内精品九九久久久精品| 久久精品国产99国产精偷| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 婷婷久久香蕉五月综合加勒比|