POJ3620
来源:互联网 发布:sketch有windows版吗 编辑:程序博客网 时间:2024/05/16 11:43
题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=3620
思路:深度搜索,搜索过的点去掉(所有点只搜索一次)
- import java.util.Scanner;
- public class Main {
- int n;
- int m;
- int k;
- boolean[][] cells;
- int max;
- int t;
- public Main() {
- Scanner scan = new Scanner(System.in);
- n = scan.nextInt();
- m = scan.nextInt();
- k = scan.nextInt();
- cells = new boolean[n][m];
- for (int i = 0; i < k; i++) {
- cells[scan.nextInt() - 1][scan.nextInt() - 1] = true;
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (cells[i][j]) {
- t = 0;
- search(i, j);
- if (t > max) {
- max = t;
- }
- }
- }
- }
- System.out.println(max);
- }
- public void search(int i, int j) {
- if (!cells[i][j]) {
- return;
- } else {
- t++;
- cells[i][j] = false;
- if (j - 1 >= 0) {
- search(i, j - 1);
- }
- if (j + 1 < m) {
- search(i, j + 1);
- }
- if (i - 1 >= 0) {
- search(i - 1, j);
- }
- if (i + 1 < n) {
- search(i + 1, j);
- }
- }
- }
- public static void main(String[] args) {
- new Main();
- }
- }
- POJ3620
- poj3620
- POJ3620
- POJ3620
- POJ3620
- poj2386 poj3620
- poj3620 DFS
- POJ3620:Avoid The Lakes
- POJ3620 Avoid The Lakes
- Avoid The Lakes--poj3620
- 搜索入门-----POJ3620
- POJ3620 Avoid The Lakes
- 【poj3620】Avoid The Lakes
- Avoid The Lakes<poj3620>
- Avoid The Lakes(poj3620)
- DFS poj3620 Avoid The Lakes
- poj3620 avoid the lakes【dfs】
- DFS poj3620(Avoid The Lakes)
- pl sql 登录初始化错误
- Idic(十分小巧的英汉发声词典)
- Tapestry学习笔记(乱码的解决方法)
- 创业话题
- 国庆19万人广场看升旗,我在其中--国庆59周年
- POJ3620
- 全排列算法汇总(C++版)
- dataGridView常用属性方法详解
- WDM驱动程序入门-Hello WDM - ZZ
- 日泽IT笔记系列1-Beginning C# Objects 从概念到代码-1
- 日泽IT笔记系列1-Beginning C# Objects 从概念到代码-2
- JAVA中的包和环境变量的设置问题
- Linux上安装VMware 6.5 tools
- 利用内存映射文件在两个进程间共享数据