hdu 1241 Oil Deposits <java>

8 篇文章 0 订阅

Oil Deposits

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5865 Accepted Submission(s): 3423


Problem Description
The 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 numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.

Input
The 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.

Output
For 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 more than 100 pockets.

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

Sample Output
  
  
0 1 2 2

Source

Recommend
Eddy
 
 

import java.util.Scanner;
 public class Main {
  static int px[]={-1,-1,-1,0,1,1,1,0};
  static int py[]={-1,0,1,1,1,0,-1,-1};
  static public void DFS(int i,int j,char a[][],boolean b[][],int m,int n){
   int k,x,y;
         b[i][j]=true;
   for(k=0;k<8;k++){
    x=i+px[k];
    y=j+py[k];
    if(x>=0&&x<m&&y<n&&y>=0){
     if(b[x][y]==false&&a[x][y]=='@'){
      DFS(x,y,a,b,m,n);
     }
    }
   }
  }
  public static void main(String[] args) {
   int m,n,i,j,k;
   Scanner oo=new Scanner(System.in);
   while(oo.hasNext()){
    m=oo.nextInt();
    n=oo.nextInt();
    if(m==0&&n==0){break;}
    String s;
    char a[][]=new char[m][n];
    for(i=0;i<m;i++){
     s=oo.next();
     for(j=0;j<n;j++){
      a[i][j]=s.charAt(j);
     }
    }
    k=0;
       boolean b[][]=new boolean[m][n];
    for(i=0;i<m;i++){
     for(j=0;j<n;j++){
      if(a[i][j]=='@'&&b[i][j]==false){
       k++;
       DFS(i,j,a,b,m,n);
      }
     }
    }
    System.out.println(k);
   }
   
  }
 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在CUDA编程中,kernel<<<>>>是用来启动并行计算的语法。在<<<>>>中,必须指定一个表达式作为参数,该表达式指定了并行计算的线程块(block)和线程(thread)的数量。这个表达式的格式可以是一个常数,也可以是一个变量或者一个计算表达式。 例如,如果想要启动一个有16个线程块和256个线程的并行计算,可以使用以下形式的表达式: kernel<<<16, 256>>>(); 其中,16表示线程块的数量,256表示每个线程块中的线程数量。 另外,如果希望在编译时指定默认的线程块和线程数量,可以使用宏定义或者模板的方式来实现。通过设置默认值,并在调用kernel时不指定表达式,就可以使用默认的线程块和线程数量。同时,也可以添加依赖关系来根据不同的条件设置不同的默认值。 总结起来,当使用kernel<<<>>>时,必须提供一个表达式来指定线程块和线程的数量。这个表达式可以是一个常数、变量或者计算表达式。另外,也可以通过设置默认值和添加依赖关系来实现更灵活的使用方式。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [玩转CUDA——提示应输入表达式](https://blog.csdn.net/gaohang_hdu/article/details/81119627)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Kconfig语法](https://download.csdn.net/download/pengfei24/4328218)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值