当前位置: 首页 > news >正文

如何建立自己的网站商城如何查网站建设时间

如何建立自己的网站商城,如何查网站建设时间,咸阳网,衡水网站建设多少钱今日任务 99. 岛屿数量 深度搜搜 99. 岛屿数量 广度搜索 100. 岛屿的最大面积 99. 岛屿数量 题目链接: 99. 岛屿数量 import java.util.Scanner;public class Main {public static int[][] dir {{0, 1},{1, 0},{-1, 0},{0, -1}};public static void dfs(boolean…


今日任务

99. 岛屿数量 深度搜搜
99. 岛屿数量 广度搜索
100. 岛屿的最大面积

99. 岛屿数量

题目链接: 99. 岛屿数量

import java.util.Scanner;public class Main {public static int[][] dir = {{0, 1},{1, 0},{-1, 0},{0, -1}};public static void dfs(boolean[][] visited, int x, int y, int[][] grid) {for (int i = 0; i < 4; i++) {int nextX = x + dir[i][0];int nextY = y + dir[i][1];if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length) {continue;}if (!visited[nextX][nextY] && grid[nextX][nextY] == 1) {visited[nextX][nextY] = true;dfs(visited, nextX, nextY, grid);}}}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int m = scanner.nextInt();int n = scanner.nextInt();int[][] grid = new int[m][n];for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {grid[i][j] = scanner.nextInt();}}boolean[][] visited = new boolean[m][n];int res = 0;for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (!visited[i][j] && grid[i][j] == 1) {res++;visited[i][j] = true;dfs(visited, i, j, grid);}}}System.out.println(res);}}

99. 岛屿数量


题目链接: 99. 岛屿数量

import java.util.Scanner;
import java.util.*;public class Main {public static int[][] dir = {{0, 1},{1, 0},{-1, 0},{0, -1}};public static void bfs(boolean[][] visited, int x, int y, int[][] grid){Queue<int[]>  queue = new LinkedList<>();queue.add(new int[]{x, y});visited[x][y] = true;while (!queue.isEmpty()) {int curX = queue.peek()[0];int curY = queue.peek()[1];queue.poll();for (int i = 0; i < 4; i++) {int nextX = curX + dir[i][0];int nextY = curY + dir[i][1];if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length) {continue;}if (!visited[nextX][nextY] && grid[nextX][nextY] == 1) {queue.add(new int[]{nextX, nextY});visited[nextX][nextY] = true;}}}}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int m = scanner.nextInt();int n = scanner.nextInt();int[][] grid = new int[m][n];for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {grid[i][j] = scanner.nextInt();}}int res = 0;boolean[][] visited = new boolean[m][n];for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (!visited[i][j] && grid[i][j] == 1) {res++;bfs(visited, i, j, grid);}}}System.out.println(res);}}


100. 岛屿的最大面积

题目链接: 100. 岛屿的最大面积

import java.util.*;
public class Main {public static int[][] dir = {{0, 1},{1, 0},{-1, 0},{0, -1}};public static int res = 0;public static void bfs(boolean[][] visited, int x, int y, int[][] grid){Queue<int[]> queue = new LinkedList<>();queue.add(new int[]{x, y});visited[x][y] = true;while (!queue.isEmpty()) {int curX = queue.peek()[0];int curY = queue.peek()[1];queue.poll();for (int i = 0; i < 4; i++) {int nextX = curX + dir[i][0];int nextY = curY + dir[i][1];if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length) {continue;}if (!visited[nextX][nextY] && grid[nextX][nextY] == 1) {res++;queue.add(new int[]{nextX, nextY});visited[nextX][nextY] = true;}}}}public static void main(String[] args){Scanner scanner = new Scanner(System.in);int m = scanner.nextInt();int n = scanner.nextInt();int[][] grid = new int[m][n];for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {grid[i][j] = scanner.nextInt();}}int max = 0;boolean[][] visited = new boolean[grid.length][grid[0].length];for (int i = 0; i < grid.length; i++) {for (int j = 0; j < grid[0].length; j++) {if (!visited[i][j] && grid[i][j] == 1) {res = 1;visited[i][j] = true;bfs(visited, i, j, grid);}max = Math.max(max, res);}}System.out.println(max);}    }

http://www.yayakq.cn/news/381367/

相关文章:

  • 平顶山高端网站建设aspcms 网站搬家
  • 网站前端建设都需要什么seo是怎么优化上去
  • 网站数据分析案例响应式网站的优缺点
  • 大型门户网站最担心的威胁是网站app开发公司
  • 优化网站排名方法什么是商城网站建设
  • 建一个图片类网站需要多少钱温州哪里有做网站的
  • 手游传奇网站发布wordpress相同字段调用
  • 城市建设档案馆网站廊坊百度推广公司地址
  • 114做网站食品网站建设规划书
  • 网站前台乱码WordPress文档转换
  • 自己有一个域名怎么做网站制作软件需要什么技术
  • 信息公开暨网站建设管理办法ngrok做网站服务器
  • 网站推广排名最新报价做网站要求的资料
  • 网络建站优化科技怎么做区块链网站
  • 佛山建网站定制费用17网站一起做网店类似的
  • 烟台网站建设开发wordpress源码安装
  • 做珠宝网站公司爱旅游网站制作
  • 家装类设计网站seo是什么专业
  • 做网站建设一条龙全包wordpress整合openid
  • 威海住房和城乡建设厅网站首页广州seo优化外包公司
  • 微信做引流网站百度主动提交工具 wordpress
  • 网站的二维码怎么做的大连seo建站
  • 自建网站h5网站被人做跳转了
  • 德阳网站优化长沙做企业网站
  • Python个人网站建设论文记事本做网站如何排版
  • 货源网站程序网页平面设计是什么
  • 如何制作一个属于自己的网站如何让域名跳转网站
  • 建局域网网站网络推广加盟
  • 建网站花费个人做网站还是公众号赚钱好
  • 网站开发四点注意事项免费软件的源代码公开吗