ZOJ1709
来源:互联网 发布:淘宝加盟诈骗罪 编辑:程序博客网 时间:2024/06/14 11:14
import java.io.BufferedInputStream;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Arrays;import java.util.Scanner;import org.omg.PortableInterceptor.INACTIVE;public class Main{ public static void main(String[] args) throws Exception{ Scanner cin = new Scanner(new BufferedInputStream(System.in)) ; PrintWriter cout = new PrintWriter(System.out); while(cin.hasNext()){ int n = cin.nextInt() , m = cin.nextInt() ; if(n == 0) break ; new Task().solve(n, m , cin , cout) ; } cout.flush() ; } }class Task{ char[][] str ; boolean[][] vis ; int[][] dir = new int[][]{{-1,0},{0,-1},{1,0},{0,1},{-1,1},{1,-1},{-1,-1},{1,1}} ; int n , m ; public boolean can(int x , int y){ return 0 <= x && x < n && 0 <= y && y < m ; } public void solve(int n , int m , Scanner cin , PrintWriter cout){ this.n = n ; this.m = m ; str = new char[n][m] ; for(int i = 0 ; i < n ; i++) str[i] = cin.next().toCharArray() ; vis = new boolean[n][m] ; int sum = 0 ; for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < m ; j++){ if(! vis[i][j] && str[i][j] == '@'){ sum++ ; dfs(i , j) ; } } } cout.println(sum) ; // cout.flush() ; } public void dfs(int x , int y){ vis[x][y] = true ; for(int i = 0 ; i < dir.length ; i++){ int nx = x + dir[i][0] ; int ny = y + dir[i][1] ; if(can(nx , ny) && ! vis[nx][ny] && str[nx][ny] == '@') dfs(nx, ny) ; } }}
0 0
- zoj1709
- ZOJ1709
- ZOJ1709
- ZOJ1709
- zoj1709
- zoj1709 bfs
- zoj1709-Oil Deposits
- poj1562 & zoj1709 - Oil Deposits (DFS)
- ZOJ1709 POJ1562 Oil Deposits,并查集
- zoj1709 Oil Deposits (DFS)递归算法
- ZOJ1709/POJ1562 油田问题/搜索/DFS
- asp 实现同一帐号,防止多人同时登录、获取在线列表、实现登录日志(可用户统计在线时长),适合用户访问量大的系统
- 用户身份认证
- Android4.0以上版本OptionsMenu无法显示图标的问题
- portal是什么?
- PHP版本特性笔记
- ZOJ1709
- 【iOS开发之Objective-C】面向对象编程--间接
- 生成算法
- 剑指offer 45-约瑟夫环
- iOS mac 终端 常用命令
- 对于node.js开发指南中博客案例的修改实现(二)--代码
- ucore操作系统lab4实验报告(理论部分)
- 配置匿名用户
- Difference Between Primes(素数打表,素数表与数表通用)