自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(23)
  • 收藏
  • 关注

原创 LeecCode 1091 JAVA BFS

class Solution { public static int shortestPathBinaryMatrix(int[][] grid) { int [][] dir = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; int minLength[][] = new int[grid.length][grid.length]; Queue<int[]> queue.

2022-02-11 01:50:45 261

原创 迷宫的最短路径 BFS JAVA

用队列实现BFS: java.util.Queue初始化一个无穷大的数INF,准备一个距离二维数组,数组规模与输入相匹配,每一元素初始化为INF。这个距离二维数组可以记录从起点到当前位置的距离,也可以作为记忆化使用(即当前位置存储的距离 != INF)。迷宫地图:/*10#S######.#......#..#.#.##.##.#.#........##.##.####....#....#.#######.#....#......####.###.....#...G#*/

2022-02-09 23:27:22 1166 1

原创 蓝桥杯 全球变暖 JAVA

import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); char[][] map = new char[n][n]; boolean[][] vis = new boolean[n][n];.

2022-02-08 16:20:32 448

原创 蓝桥杯 全球变暖 DFS&BFS

最后一个过不了干啥啥不行,写烂代码第一名我就是记录一下,建议别看import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); char[][] map = new char[n][n];

2022-02-08 15:35:42 543

原创 连续子数组的最大和 记录一下糟糕的算法

蛮力法肯定会超时,只能过50%用例 public static int FindGreatestSumOfSubArray(int[] array) { int max = array[0]; int index = 0; while (index <= array.length - 1) { int index2 = index; int sum = 0; while

2022-02-07 01:40:47 255

原创 DFS LeetCode 547 省份数量(原题名: Friend Circles)

class Solution { private int n = 0; public int findCircleNum(int[][] M) { n = M.length; int res = 0; boolean[] vis = new boolean[n]; for (int i = 0; i < n; i++) { if (vis[i] == false) { .

2022-02-04 02:24:42 298

原创 DFS LeetCode 417

class Solution { private int[][] direction = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; public List<List<Integer>> pacificAtlantic(int[][] grid) { List<List<Integer>> list = new ArrayList<>(); int[][] recLU.

2022-02-04 01:09:10 299

原创 DFS Leetcode 200

class Solution { public int numIslands(char[][] grid) { int res = 0; for(int i = 0; i< grid.length;i++){ for(int j = 0; j<grid[0].length;j++){ if(dfs(grid,i,j)){ res+=1; .

2022-02-03 17:21:59 172

原创 DFS Leetcode 695

class Solution { public int maxAreaOfIsland(int[][] grid) { int res = 0; int xLen = grid.length; int yLen = grid[0].length; for (int i = 0; i < xLen; i++) { for (int j = 0; j < yLen; j++) { .

2022-02-03 16:31:25 317

原创 蓝桥杯 正则问题 JAVA

import java.util.*;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] arrC = sc.next().toCharArray(); Stack<Character> sk = new Stack<>(); for (int i.

2022-02-02 16:42:15 395

原创 蓝桥杯 日期问题 JAVA

有一说一,这题30分,要考虑的点还是很多的。下面的写法有点麻烦。import java.util.Arrays;import java.util.Scanner;import java.util.TreeSet;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.next(

2022-02-01 04:19:33 428

原创 蓝桥杯 方格分割 JAVA

public class Main { static int res = 0; static boolean [][] rec = new boolean[7][7]; static int[][] dir = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; public static void main(String[] args).

2022-01-31 04:34:21 6993 1

原创 蓝桥杯 迷宫 2017 A

原题数据本来是char数组误写为String数组了,将就看吧。注释的是输入输出功能。public class Main { public static void main(String[] args) {// Scanner scan = new Scanner(System.in);// int N = scan.nextInt();// int M = scan.nextInt(); int N = 10;

2022-01-30 02:08:17 735

原创 dfs: POJ 2386 JAVA

/*10 12W . . . . . . . . W W .. W W W . . . . . W W W. . . . W W . . . W W .. . . . . . . . . W W .. . . . . . . . . W . .. . W . . . . . . W . .. W . W . . . . . W W .W . W . W . . . . . W .. W . W . . . . . . W .. . W . . . . . . . W .*/im.

2022-01-29 05:22:01 564

原创 全排列应用:输出子集

public class Main { public static void main(String[] args) { String s = "12345"; char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { char [] cc = new char[i+1]; for (int j = 0; j < cc..

2022-01-28 21:50:53 6059

原创 全排列 JAVA实现

需要注意是恢复(回溯回去)。public class Main { public static void main(String[] args) { String s = "ABC"; permutation(0,s.length()-1,s.toCharArray()); } private static void permutation(int left, int right, char[] c) { if(left ==

2022-01-28 21:42:50 193

原创 斐波那契数列的记忆化

用途:复杂度优化。public class Main { public static void main(String[] args) { System.out.println(fib(20)); } static int fib(int n){ int [] res = new int[25]; if(n==1 | n==2){ res[n] = 1; return res[n

2022-01-28 21:23:09 213

原创 蓝桥杯 等差数列

先排序,然后两两数之间相减得到这个结果的次数最多的就是公差。然后再用(数组最大值-最小值)/公差 + 1 就是项数。import java.util.ArrayList;import java.util.Scanner;import java.util.TreeSet;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in)

2022-01-27 21:37:18 6226

原创 蓝桥杯 完全二叉树的权值

本题的关键点在于注意完全二叉树并非满二叉树。可以根据深度强转整数进行判断:if(Math.log(n+1)/Math.log(2) > (int)(Math.log(n+1)/Math.log(2))){}完整代码:import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System

2022-01-27 00:17:39 819

原创 蓝桥杯 特别数的和

做法是按位取余,这里换个写法。转换为StringBuilder:public class Main { public static void main(String[] args) { int sum = 0; Scanner scan = new Scanner(System.in); int n = scan.nextInt(); for (int i = 1; i <= n; i++) { ..

2022-01-26 21:47:46 161

原创 蓝桥杯 数的分解

times爆了 填空题public class Main { public static void main(String[] args) { int count = 0; for (int i = 1; i <= 1999; i++) { StringBuilder si = new StringBuilder(String.valueOf(i)); if(si.indexOf("2") == -1 &am

2022-01-25 22:12:32 115

原创 网站是如何进行访问的

输入一个域名,回车后发生了什么?

2021-09-10 09:37:47 2657

原创 关于PAT 1001 害死人不偿命的(3n+1)猜想的疑问

卡拉兹(Callatz)猜想:是对任何一个正整数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)砍掉一半。这样一直反复砍下去,最后一定在某一步得到n=1。题目描述:我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过 1000 的正整数n,简单地数一下,需要多少步(砍几下)才能得到n=1?代码一:#include<stdio.h>int main(){ int n=0,i=0; scanf("%d",&n); whil...

2021-09-03 11:25:09 165

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除