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

汕头网站推广费用做网站首页的图片素材

汕头网站推广费用,做网站首页的图片素材,网站开发项目流程书,做电商搜素材网站都是什么1.装水问题 有一个 异形 容器#xff0c;用一个 n * n 的二维数组来表示。其中 1 表示容器实心部分#xff0c; 0 表示空心部分。现使用此容器装水#xff0c;能装多少水#xff08;每个元素都表示一份水#xff0c;只有有挡板的部分能装水#xff09;#xff1f; publi…1.装水问题 有一个 异形 容器用一个 n * n 的二维数组来表示。其中 1 表示容器实心部分 0 表示空心部分。现使用此容器装水能装多少水每个元素都表示一份水只有有挡板的部分能装水 public class Work1001 {public static void main(String[] args) {int[][] arr {{0, 0, 1, 0, 0, 0, 0},{0, 0, 1, 0, 0, 0, 0},{0, 0, 1, 0, 1, 0, 0},{1, 0, 1, 0, 1, 0, 1},{1, 1, 1, 1, 1, 1, 1},};int sum 0;for (int i 0; i arr.length; i) {int count 0;int v 0;for (int j 0; j arr[0].length; j) {if (arr[i][j] 1) {count;if (count 2) {count 1;sum v;v 0;}} else {if (count 0) {v;}}}}System.out.println(sum);} }思考若是使用一个一维数组来表示实心部分高度该如何计算(int[] arr {2, 5, 1, 2, 3, 4, 7, 2}; ) import java.util.Arrays;public class Work10012 {public static void main(String[] args) {int[] arr {2, 5, 1, 2, 3, 4, 7, 2};int len Arrays.stream(arr).max().orElse(0);// 定义二维数组int[][] arr1 new int[len][arr.length];// 将一维数组转为二维数组for (int i len - 1; i 0; i--) {for (int j 0; j arr.length; j) {if (arr[j] 0) {arr1[i][j] 1;arr[j]--;}}}// 计算能装多少水int sum 0;for (int i 0; i arr1.length; i) {int count 0;int v 0;for (int j 0; j arr1[0].length; j) {if (arr1[i][j] 1) {count;if (count 2) {count 1;sum v;v 0;}} else {if (count 0) {v;}}}}System.out.println(sum);} }Arrays.stream(arr).max().orElse(0) 这行代码使用了 Java 8 中的流式操作。每个部分的含义 对于给定的数组 arrArrays.stream(arr) 方法将其转换为一个流Stream对象。流是用于在一系列元素上执行操作的一种高级抽象。 然后我们使用 .max() 方法来获取流中的最大值。这将返回一个 Optional 类型的对象它可以包含一个整数值如果流中有元素或者为空如果流为空。 最后我们使用 .orElse(0) 方法指定一个默认值。如果 Optional 对象为空则返回指定的默认值否则返回 Optional 中包含的值。 在这个特定的例子中如果数组 arr 不为空.max() 方法将返回一个 Optional 对象其中包含数组中的最大值。如果数组为空.max() 方法将返回一个空的 Optional 对象。接着.orElse(0) 方法将被调用如果 Optional 为空则返回默认值 0。 整个表达式 Arrays.stream(arr).max().orElse(0) 的作用是获取数组 arr 中的最大值如果数组为空则返回默认值 0。 2. 迷宫游戏【拓展】 在一个二维数组中0 表示空地1 表示墙壁9 表示目标点。你的任务是从起始点 (0, 0)出发判断是否能够到达目标点不能斜着移动。 public class Work1002 {public static void main(String[] args) {int[][] arr {{0, 0, 0, 0, 0},{1, 1, 0, 1, 0},{0, 0, 0, 0, 0},{0, 1, 1, 1, 1},{0, 0, 0, 0, 9}};boolean canReach canReachTarget(arr);System.out.println(canReach ? 可以到达目标点 : 无法到达目标点);}public static boolean canReachTarget(int[][] maze) {int m maze.length; // 行数int n maze[0].length; // 列数boolean[][] visited new boolean[m][n]; // 标记数组记录是否访问过return dfs(maze, 0, 0, visited);}private static boolean dfs(int[][] maze, int i, int j, boolean[][] visited) {if (i 0 || i maze.length || j 0 || j maze[0].length || maze[i][j] 1 || visited[i][j]) {return false; // 越界、遇到墙壁或已经访问过的位置返回false}if (maze[i][j] 9) {System.out.println(到达目标点 ( i , j ));return true; // 找到目标点返回true}visited[i][j] true; // 标记当前位置为已访问System.out.println(移动到位置 ( i , j ));// 分别尝试上、下、左、右四个方向的移动boolean canReach dfs(maze, i - 1, j, visited) ||dfs(maze, i 1, j, visited) ||dfs(maze, i, j - 1, visited) ||dfs(maze, i, j 1, visited);visited[i][j] false; // 回溯取消当前位置的标记return canReach;} }3. 九宫格求和 一个二维数组找出最小值求以最小值为中心的九宫格的和如果九宫格空缺空缺位置用0补充。 public class Learn1001 {public static void main(String[] args) {int[][] arr {{9, 10, 11, 12},{100, 20, 30, 40},{13, 14, 15, 16},{5, 6, 7, 10},};int n arr.length;int m arr[0].length;// 求最小值int[] index new int[2];int min arr[0][0];for (int i 0; i n; i) {for (int j 0; j m; j) {if (arr[i][j] min){min arr[i][j];index[0] i;index[1] j;}}}System.out.println(Arrays.toString(index));int sum 0;for (int i index[0] - 1; i index[0] 1; i) {for (int j index[1] - 1; j index[1] 1; j) {if (i 0 i n j 0 j m) {sum arr[i][j];} else {sum 0;}}}System.out.println(sum);} }
http://www.hkea.cn/news/14402157/

相关文章:

  • 网站建设目标和功能介绍施工企业成本管理的方法与手段
  • 做直播导航网站有哪些重庆网站建设有限公司
  • 网站维护是什么工作公司网站建设空间
  • 建设企业功能网站松江外贸网站建设
  • 网站设计高大上山东省作风建设网站
  • 专业的营销网站建设公司flash翻页效果网站模板
  • 网站空间管理面板淘宝网站开始怎么做
  • 北京住房与城乡建设厅网站微信官方网站怎么进入
  • 网站建设 中企动力公司网站恶意点击
  • 制作企业网站定向推广
  • 重庆神态网站建设wordpress搬家后重新安装
  • 各大网站域名大全张家港做网站公司
  • 给个营销型网站聚名网查询
  • 互动网站策划网站开发基本构成
  • 什么网站开发外贸客户襄阳网站seo技巧
  • 怎么选择赣州网站建设电子商务做网站
  • 做网站用什么服务器好wordpress 迁移 插件
  • 喜满堂网站建设wordpress企业咨询模板
  • 手机网站如何制作视频网站用什么cms
  • 优化网站关键词百度经验app
  • 有没有电脑做兼职的网站临沂 网站优化
  • 自己能不能做个网站为什么要选择做花卉网站
  • 做古玩生意哪些网站好ppt制作入门教程
  • 网站源码搭建网站休闲农业有哪些网络营销方式
  • 成都网站快速排名提升哈尔滨优惠的网站建设
  • 校园网站如何管理课程网站建设目标任务
  • 东营网站建设预算价格骏域网站建设专家电话
  • jquery 个人网站wordpress oss 防盗链
  • 广州网站建设制作网站建设培训赚钱吗
  • wordpress博客文章图片美化短视频搜索优化