• <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 閱讀(1515) 評論(1)  編輯 收藏 引用 所屬分類: 算法題解
            国产精品熟女福利久久AV| 亚洲午夜无码AV毛片久久| 性欧美大战久久久久久久久| 亚洲精品午夜国产va久久| 国产99久久久国产精免费| 99久久国产综合精品成人影院| 99久久综合国产精品二区| 亚洲精品99久久久久中文字幕| 久久狠狠爱亚洲综合影院| 99久久er这里只有精品18| 久久99精品久久久久久9蜜桃 | 久久精品国产AV一区二区三区| 日韩人妻无码精品久久免费一 | 久久人人爽人人爽人人片AV不| 亚洲AV乱码久久精品蜜桃| 久久精品夜色噜噜亚洲A∨| 久久久久久久久久久| 国产激情久久久久影院| 日韩精品久久久久久久电影蜜臀| 中文字幕亚洲综合久久| 欧美亚洲色综久久精品国产| 伊人久久大香线焦综合四虎| 久久午夜无码鲁丝片| 久久亚洲欧洲国产综合| 国产精品美女久久久久久2018| 久久久久国产成人精品亚洲午夜| 国产综合久久久久久鬼色| 亚洲国产小视频精品久久久三级| 草草久久久无码国产专区| 九九久久99综合一区二区| 国内高清久久久久久| 国产精品久久久久a影院| 久久久精品日本一区二区三区| 97久久精品人人做人人爽| 色偷偷888欧美精品久久久| 99re这里只有精品热久久| 久久国产精品一国产精品金尊| 国内精品久久久久久久97牛牛| 国产亚洲精品美女久久久| 91精品国产91久久久久福利| 精品久久8x国产免费观看|