Hdu1241 (Oil Deposits)

Source: Internet
Author: User

Hdu1241 (Oil Deposits)

 

Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. geoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. it then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. if two pockets are adjacent, then they are part of the same oil deposit. oil deposits can be quite large and may contain in numerous pockets. your job is to determine how many different oil deposits are contained in a grid.

InputThe input file contains one or more grids. each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. if m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. following this are m lines of n characters each (not counting the end-of-line characters ). each character corresponds to one plot, and is either '*', representing the absence of oil, or '@', representing an oil pocket.

OutputFor each grid, output the number of distinct oil deposits. two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. an oil deposit will not contain in more than 100 pockets.

Sample Input
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5 ****@*@@*@*@**@@@@*@@@**@0 0 

Sample Output
0122

 

 

Import java. util. extends; public class SearchMethodBFS {public static void main (String [] args) {Using SC = new using (System. in); while (SC. hasNext () {int m = SC. nextInt (); // line int n = SC. nextInt (); // column if (m = 0) {break;} // input graph (initialization) plot plots [] [] = new Plot [m] [n]; for (int I = 0; I
 
  
= 0 & px
  
   
= 0 & py
   
    
1) {for (int I = 0; I
    
     

 

Optimized: cyclic queue

 

Import java. util. extends; public class SearchMethodBFS {public static void main (String [] args) {Using SC = new using (System. in); while (SC. hasNext () {int m = SC. nextInt (); // line int n = SC. nextInt (); // column if (m = 0) {break;} // input graph (initialization) PPlot plots [] [] = new PPlot [m] [n]; for (int I = 0; I
      
       
= 0 & px
       
        
= 0 & py
        
         

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.