代码随想录算法训练营第五十二天| [KC]100. 岛屿的最大面积、101. 孤岛的总面积、102. 沉没孤岛、103. 水流问题

[KamaCoder] 100. 岛屿的最大面积

[KamaCoder] 100. 岛屿的最大面积 文章解释

题目描述

给定一个由 1(陆地)和 0(水)组成的矩阵,计算岛屿的最大面积。岛屿面积的计算方式为组成岛屿的陆地的总数。岛屿由水平方向或垂直方向上相邻的陆地连接而成,并且四周都是水域。你可以假设矩阵外均被水包围。

输入描述

第一行包含两个整数 N, M,表示矩阵的行数和列数。后续 N 行,每行包含 M 个数字,数字为 1 或者 0,表示岛屿的单元格。

输出描述

输出一个整数,表示岛屿的最大面积。如果不存在岛屿,则输出 0。

输入示例
4 5
1 1 0 0 0
1 1 0 0 0
0 0 1 0 0
0 0 0 1 1
输出示例
4

样例输入中,岛屿的最大面积为 4。

数据范围:

1 <= M, N <= 50。

[KamaCoder] 100. 岛屿的最大面积

自己看到题目的第一想法

    深搜一下, 每次遇到没有访问过的陆地, 就把面积加 1, 同时继续遍历与该节点相邻的陆地, 将相邻陆地的面积累加到当前陆地上, 并返回给上一级陆地, 最终完成统计.

看完代码随想录之后的想法

    基本上是类似的.

import java.util.Scanner;
import java.util.Deque;
import java.util.LinkedList;

public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        while (scanner.hasNext()) {
            int rowCount = scanner.nextInt();
            int columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        int result = 0;
        for (int x = 0; x < nodes.length; x++) {
            for (int y = 0; y < nodes[x].length; y++) {
                if (visited[x][y] || nodes[x][y] != 1) {
                    continue;
                }
                visited[x][y] = true;
                result = Math.max(result, dfs(nodes, visited, x, y));
            }
        }
        System.out.println(result);
    }
    private static int dfs(int[][] nodes, boolean visited[][], int x, int y) {
        int newX;
        int newY;
        int result = 1;
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                continue;
            }
            if (visited[newX][newY] || nodes[newX][newY] != 1) {
                continue;
            }
            visited[newX][newY] = true;
            result += dfs(nodes, visited, newX, newY);
        }
        return result;
    }
}
// for 循环清爽版
import java.util.Scanner;
import java.util.Deque;
import java.util.LinkedList;

public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        while (scanner.hasNext()) {
            int rowCount = scanner.nextInt();
            int columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        int result = 0;
        for (int x = 0; x < nodes.length; x++) {
            for (int y = 0; y < nodes[x].length; y++) {
                // 这里变得简单一些
                result = Math.max(result, dfs(nodes, visited, x, y));
            }
        }
        System.out.println(result);
    }
    private static int dfs(int[][] nodes, boolean visited[][], int x, int y) {
        // 判断都已到下面两个 if 里了, 同时每次会多一些递归调用.
        if (x < 0 || x >= nodes.length || y < 0 || y >= nodes[x].length) {
            return 0;
        }
        if (visited[x][y] || nodes[x][y] != 1) {
            return 0;
        }
        visited[x][y] = true;
        int newX;
        int newY;
        int result = 1;
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            // 这里变得简单一些
            result += dfs(nodes, visited, newX, newY);
        }
        return result;
    }
}
import java.util.Scanner;
import java.util.Deque;
import java.util.LinkedList;

// bfs 版本
public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        while (scanner.hasNext()) {
            int rowCount = scanner.nextInt();
            int columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        int result = 0;
        for (int x = 0; x < nodes.length; x++) {
            for (int y = 0; y < nodes[x].length; y++) {
                // 这里变得简单一些
                result = Math.max(result, bfs(nodes, visited, x, y));
            }
        }
        System.out.println(result);
    }
    private static int bfs(int[][] nodes, boolean visited[][], int x, int y) {
        if (x < 0 || x >= nodes.length || y < 0 || y >= nodes[x].length) {
            return 0;
        }
        if (visited[x][y] || nodes[x][y] != 1) {
            return 0;
        }
        Deque<Integer> toNodes = new LinkedList<>();
        toNodes.addLast(x);
        toNodes.addLast(y);
        visited[x][y] = true;
        int result = 0;
        while (!toNodes.isEmpty()) {
            x = toNodes.pop();
            y = toNodes.pop();
            result++;
            int newX;
            int newY;
            for (int i = 0; i < dir.length; i++) {
                newX = x + dir[i][0];
                newY = y + dir[i][1];
                // 这里变得简单一些
                // 判断都已到下面两个 if 里了, 同时每次会多一些递归调用.
                if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                    continue;
                }
                if (visited[newX][newY] || nodes[newX][newY] != 1) {
                    continue;
                }
                toNodes.addLast(newX);
                toNodes.addLast(newY);
                visited[newX][newY] = true;
            }
        }
        return result;
    }
}

自己实现过程中遇到哪些困难

    hhh, 卡神说你不要 pop 了再更新 visited 数组, 不然节点会重复计算... 小心翼翼之后, 还是在某天过后忘记了~ 还好一下子就意识到问题所在, 排查起来也快.

[KamaCoder] 101. 孤岛的总面积

[KamaCoder] 101. 孤岛的总面积 文章解释

[KamaCoder] 101. 孤岛的总面积

自己看到题目的第一想法

    dfs 它! 如果当前遇到了边缘节点, 则面积返回0. 上层节点发现下层递归返回面积为 0, 则知道当前遇到了边缘, 这时候需要继续递归其他子节点做上标记, 同时记录住当前岛屿非孤岛.

import java.util.Scanner;
// 容易超时版本
public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        while (scanner.hasNext()) {
            int rowCount = scanner.nextInt();
            int columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        int result = 0;
        for (int i = 0; i < nodes.length; i++) {
            for (int j = 0; j < nodes[i].length; j++) {
                if (visited[i][j] || nodes[i][j] != 1) {
                    continue;
                }
                result += dfs(nodes, visited, i, j);
            }
        }
        System.out.println(result);
    }
    
    private static int dfs(int[][] nodes, boolean[][] visited, int x, int y) {
        visited[x][y] = true;
        int result = 0;
        int newX;
        int newY;
        boolean isNotLonelyIsland = false;// 没有什么是一个变量处理不了的
        if (x == 0 || x == nodes.length - 1 || y == 0 || y == nodes[x].length - 1) {
            isNotLonelyIsland = true;
        } 
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                continue;
            }
            if (visited[newX][newY] || nodes[newX][newY] != 1) {
                continue;
            }
            int childResult = dfs(nodes, visited, newX, newY);
            if (childResult == 0) {// 如果不行就两个...
                isNotLonelyIsland = true;
            }
            result += childResult;
        }
        if (isNotLonelyIsland) {
            return 0;
        }
        return result + 1;
    }
}
import java.util.Scanner;
import java.util.Deque;
import java.util.LinkedList;

// bfs 版本: 第一次必超时版本.
public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        while (scanner.hasNext()) {
            int rowCount = scanner.nextInt();
            int columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        int result = 0;
        for (int i = 0; i < nodes.length; i++) {
            for (int j = 0; j < nodes[i].length; j++) {
                result += bfs(nodes, visited, i, j);
            }
        }
        System.out.println(result);
    }
    
    private static int bfs(int[][] nodes, boolean[][] visited, int x, int y) {
        if (x < 0 || x >= nodes.length || y < 0 || y >= nodes[x].length) {
            return 0;
        }
        if (visited[x][y] || nodes[x][y] != 1) {
            return 0;
        }
        Deque<Integer> childNodes = new LinkedList<>();
        childNodes.addLast(x);
        childNodes.addLast(y);
        visited[x][y] = true;
        int result = 0;
        boolean isNotLonelyIsland = false;
        if (x == 0 || x == nodes.length - 1 || y == 0 || y == nodes[x].length - 1) {
            isNotLonelyIsland = true;
        }
        while (!childNodes.isEmpty()) {
            x = childNodes.pop();
            y = childNodes.pop();
            int newX;
            int newY;
            result++;
            for (int i = 0; i < dir.length; i++) {
                newX = x + dir[i][0];
                newY = y + dir[i][1];
                if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                    continue;
                }
                if (visited[newX][newY] || nodes[newX][newY] != 1) {
                    continue;
                }
                if (newX == 0 || newX == nodes.length - 1 || newY == 0 || newY == nodes[newX].length - 1) {
                    isNotLonelyIsland = true;
                }
                childNodes.addLast(newX);
                childNodes.addLast(newY);
                visited[newX][newY] = true;
            }
        }
        
        return isNotLonelyIsland ? 0 : result;
    }
}

 

看完代码随想录之后的想法

    先沉没所有的非孤岛, 再计算孤岛, great!

import java.util.Scanner;

// 稳定超时版本~
public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        int rowCount = 0;
        int columnCount = 0;
        while (scanner.hasNext()) {
            rowCount = scanner.nextInt();
            columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        for (int i = 0; i < rowCount; i++) {
            if (nodes[i][0] == 1) {
                dfs(nodes, i, 0);
            }
            if (nodes[i][columnCount - 1] == 1) {
                dfs(nodes, i, columnCount - 1);
            }
        }
        for (int i = 0; i < columnCount; i++) {
            if (nodes[0][i] == 1) {
                dfs(nodes, 0, i);
            }
            if (nodes[rowCount - 1][i] == 1) {
                dfs(nodes, rowCount - 1, i);
            }
        }
        int result = 0;
        for (int i = 0; i < nodes.length; i++) {
            for (int j = 0; j < nodes[i].length; j++) {
                if (nodes[i][j] != 1) {
                    continue;
                }
                result += dfs(nodes, i, j);
            }
        }
        System.out.println(result);
    }
    private static int dfs(int[][] nodes, int x, int y) {
        if (nodes[x][y] != 1) {
            return 0;
        }
        int result = 1;
        int newX;
        int newY;
        
        nodes[x][y] = 0;
        
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                continue;
            }
            if (nodes[newX][newY] != 1) {
                continue;
            }
            result += dfs(nodes, newX, newY);
        }
        return result;
    }
}
import java.util.Scanner;

// 有概率超时
public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    private static int result = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        int rowCount = 0;
        int columnCount = 0;
        while (scanner.hasNext()) {
            rowCount = scanner.nextInt();
            columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        for (int i = 0; i < rowCount; i++) {
            if (nodes[i][0] == 1) {
                dfs(nodes, i, 0);
            }
            if (nodes[i][columnCount - 1] == 1) {
                dfs(nodes, i, columnCount - 1);
            }
        }
        for (int i = 0; i < columnCount; i++) {
            if (nodes[0][i] == 1) {
                dfs(nodes, 0, i);
            }
            if (nodes[rowCount - 1][i] == 1) {
                dfs(nodes, rowCount - 1, i);
            }
        }
        result = 0;
        for (int i = 0; i < nodes.length; i++) {
            for (int j = 0; j < nodes[i].length; j++) {
                if (nodes[i][j] != 1) {
                    continue;
                }
                dfs(nodes, i, j);
            }
        }
        System.out.println(result);
    }
    // 不要返回值才能通过T_T
    private static void dfs(int[][] nodes, int x, int y) {
        int newX;
        int newY;
        
        nodes[x][y] = 0;
        result++;
        
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                continue;
            }
            if (nodes[newX][newY] != 1) {
                continue;
            }
            dfs(nodes, newX, newY);
        }
        return;
    }
}

自己实现过程中遇到哪些困难

    超时了~

[KamaCoder] 102. 沉没孤岛

[KamaCoder] 102. 沉没孤岛 文章解释

题目描述

给定一个由 1(陆地)和 0(水)组成的矩阵,岛屿指的是由水平或垂直方向上相邻的陆地单元格组成的区域,且完全被水域单元格包围。孤岛是那些位于矩阵内部、所有单元格都不接触边缘的岛屿。

现在你需要将所有孤岛“沉没”,即将孤岛中的所有陆地单元格(1)转变为水域单元格(0)。

输入描述

第一行包含两个整数 N, M,表示矩阵的行数和列数。

之后 N 行,每行包含 M 个数字,数字为 1 或者 0,表示岛屿的单元格。

输出描述

输出将孤岛“沉没”之后的岛屿矩阵。 注意:每个元素后面都有一个空格

输入示例
4 5
1 1 0 0 0
1 1 0 0 0
0 0 1 0 0
0 0 0 1 1
输出示例
1 1 0 0 0
1 1 0 0 0
0 0 0 0 0
0 0 0 1 1
提示信息

将孤岛沉没。

数据范围:

1 <= M, N <= 50。

[KamaCoder] 102. 沉没孤岛

自己看到题目的第一想法

    和孤岛总面积一样, 先标记一一下边缘陆地, 再把非边缘陆地变为水. 这样的话需要二维数组 visited[][] 以及 boolean needSink 来辅助判断是否需要沉没当前节点.

看完代码随想录之后的想法

    将边缘陆地修改为2, 沉没为1的孤岛, 重置边缘陆地为1. Great!

    确实没有想着去复用数据~

import java.util.Scanner;

public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        int rowCount = 0;
        int columnCount = 0;
        while (scanner.hasNext()) {
            rowCount = scanner.nextInt();
            columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        for (int i = 0; i < rowCount; i++) {
            if (nodes[i][0] == 1) {
                dfs(nodes, i, 0);
            }
            if (nodes[i][columnCount - 1] == 1) {
                dfs(nodes, i, columnCount - 1);
            }
        }
        
        for (int i = 0; i < columnCount; i++) {
            if (nodes[0][i] == 1) {
                dfs(nodes, 0, i);
            }
            if (nodes[rowCount - 1][i] == 1) {
                dfs(nodes, rowCount - 1, i);
            }
        }
        
        for (int i = 0; i < rowCount; i++) {
            for (int j = 0; j < columnCount; j++) {
                if (nodes[i][j] == 1) {
                    nodes[i][j] = 0;
                }
                if (nodes[i][j] == 2) {
                    nodes[i][j] = 1;
                }
                if (j != columnCount - 1) {
                    System.out.print(nodes[i][j] + " ");
                } else {
                    System.out.println(nodes[i][j]);
                }
            }
        }
    }
    private static void dfs(int[][] nodes, int x, int y) {
        nodes[x][y] = 2;
        int newX;
        int newY;
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                continue;
            }
            if (nodes[newX][newY] == 2 || nodes[newX][newY] == 0) {
                continue;
            }
            dfs(nodes, newX, newY);
        }
    }
}

自己实现过程中遇到哪些困难

    无.

[KamaCoder] 103. 水流问题

[KamaCoder] 103. 水流问题 文章解释

题目描述

现有一个 N × M 的矩阵,每个单元格包含一个数值,这个数值代表该位置的相对高度。矩阵的左边界和上边界被认为是第一组边界,而矩阵的右边界和下边界被视为第二组边界。

矩阵模拟了一个地形,当雨水落在上面时,水会根据地形的倾斜向低处流动,但只能从较高或等高的地点流向较低或等高并且相邻(上下左右方向)的地点。我们的目标是确定那些单元格,从这些单元格出发的水可以达到第一组边界和第二组边界。

输入描述

第一行包含两个整数 N 和 M,分别表示矩阵的行数和列数。 

后续 N 行,每行包含 M 个整数,表示矩阵中的每个单元格的高度。

输出描述

输出共有多行,每行输出两个整数,用一个空格隔开,表示可达第一组边界和第二组边界的单元格的坐标,输出顺序任意。

输入示例
5 5
1 3 1 2 4
1 2 1 3 2
2 4 7 2 1
4 5 6 1 1
1 4 1 2 1
输出示例
0 4
1 3
2 2
3 0
3 1
3 2
4 0
4 1

数据范围:

1 <= M, N <= 100。

[KamaCoder] 103. 水流问题

自己看到题目的第一想法

    要怎么才能找到高点呢? 毫无头绪

看完代码随想录之后的想法

    逆流而上! 爬不动的时候停止. 如果从两个方向逆流而上都能到达的节点, 水就能从这个节点留到两个方向去.

import java.util.Scanner;
// 不知道还能怎么剪枝了, 永远的超时~
public class Main {
    private static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] nodes = null;
        boolean[][] visited = null;
        int rowCount = 0;
        int columnCount = 0;
        while (scanner.hasNext()) {
            rowCount = scanner.nextInt();
            columnCount = scanner.nextInt();
            nodes = new int[rowCount][columnCount];
            visited = new boolean[rowCount][columnCount];
            for (int i = 0; i < rowCount; i++) {
                for (int j = 0; j < columnCount; j++) {
                    nodes[i][j] = scanner.nextInt();
                }
            }
        }
        boolean[][] firstVisited = new boolean[rowCount][columnCount];
        boolean[][] secondVisited = new boolean[rowCount][columnCount];
        for (int i = 0; i < rowCount; i++) {
            if (!firstVisited[i][0]) {
                dfs(nodes, firstVisited, i, 0);
            }
            if (!secondVisited[i][columnCount - 1]) {
                dfs(nodes, secondVisited, i, columnCount - 1);
            }
        }
        for (int i = 0; i < columnCount; i++) {
            if (!firstVisited[0][i]) {
                dfs(nodes, firstVisited, 0, i);
            }
            if (!secondVisited[rowCount - 1][i]) {
                dfs(nodes, secondVisited, rowCount - 1, i);
            }
        }
        for (int i = 0; i < rowCount; i++) {
            for (int j = 0; j < columnCount; j++) {
                if (firstVisited[i][j] && secondVisited[i][j]) {
                    System.out.println(i + " " + j);
                }
            }
        }
    }
    private static void dfs(int[][] nodes, boolean[][] visited, int x, int y) {
        if (visited[x][y]) {
            return;
        }
        visited[x][y] = true;
        int newX;
        int newY;
        for (int i = 0; i < dir.length; i++) {
            newX = x + dir[i][0];
            newY = y + dir[i][1];
            if (newX < 0 || newX >= nodes.length || newY < 0 || newY >= nodes[newX].length) {
                continue;
            }
            if (visited[newX][newY] || nodes[x][y] > nodes[newX][newY]) {
                continue;
            }
            dfs(nodes, visited, newX, newY);
        }
    }
}

自己实现过程中遇到哪些困难

    超时了~ 没 AC~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/752594.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

开放式耳机哪个牌子好?2024热门红榜开放式耳机测评真实篇!

当你跟朋友们聊天时&#xff0c;他们经常抱怨说长时间戴耳机会令耳朵感到不适,后台也有很多人来滴滴我&#xff0c;作为一位致力于开放式耳机的测评博主&#xff0c;在对比了多款开放式耳机之后&#xff0c;你开放式耳机在保护听力方面确实有用。开放式的设计有助于减轻耳道内的…

自适应蚁群算法优化的攀爬机器人的路径规划

大家好&#xff0c;我是带我去滑雪&#xff01; 攀爬机器人是一种能够在复杂环境中自主移动和攀爬的具有广阔应用前景的智能机器人&#xff0c;具有较强的应用潜力和广泛的研究价值。随着科技的不断发展&#xff0c;攀爬机器人在许多领域中的应用越来越广泛&#xff0c;例如建筑…

FastGPT 手动部署错误:MongooseServerSelectionError: getaddrinfo EAI_AGAIN mongo

在运行 FastGPT 时&#xff0c;mongodb 报如下错误&#xff1a; MongooseServerSelectionError: getaddrinfo EAI_AGAIN mongo 这是因为 mongo 没有解析出来&#xff0c;在 hosts 文件中添加如下信息&#xff1a; 127.0.0.1 mongo 重新运行 FastGPT 即可。 参考链接&#xff…

力扣随机一题 位运算/滑动窗口/数组

博客主页&#xff1a;誓则盟约系列专栏&#xff1a;IT竞赛 专栏关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d;收藏⭐评论✍ 3191.使二进制数组全部等于1的最少操作次数I【中等】 题目&#xff1a; 给…

C语言力扣刷题7——删除排序链表中的重复元素 II——[快慢双指针法]

力扣刷题7——删除排序链表中的重复元素 II——[快慢双指针法] 一、博客声明二、题目描述三、解题思路1、思路说明 四、解题代码&#xff08;附注释&#xff09; 一、博客声明 找工作逃不过刷题&#xff0c;为了更好的督促自己学习以及理解力扣大佬们的解题思路&#xff0c;开辟…

STM32将外部SDRAM空间作为系统堆(Heap)空间

概述 stm32可以外扩很大的sram&#xff0c;常见外部sram的初始化函数一般是c语言写的&#xff0c;默认写在main函数里面。stm32初始化首先进入汇编代码startup_stm32f429xx.s&#xff0c;在汇编代码中Reset_Handler&#xff08;复位中断服务程序&#xff09;里面先调用了Syste…

光明致优尊耀呈现“柏林爱乐在上海”音乐会正式开幕,奏响盛夏狂热乐章

2024年6月26日&#xff0c;由光明致优尊耀呈现的中国上海国际艺术节特别项目“柏林爱乐在上海”音乐会正式开幕。暌违七年&#xff0c;世界顶级交响乐团——柏林爱乐乐团再度访沪&#xff0c;在首席指挥基里尔别特连科率领下&#xff0c;正式在中国上海国际艺术节登台演出&…

Talk|CityU 助理教授马佳葳: CVPR 2024, 基于多模态理解的混合数据专家模型

本期为TechBeat人工智能社区第604期线上Talk。 北京时间6月27日(周四)20:00&#xff0c;香港城市大学助理教授—马佳葳的Talk已经准时在TechBeat人工智能社区开播&#xff01; 他与大家分享的主题是: “基于多模态理解的混合数据专家模型”&#xff0c;他向大家介绍了混合数据专…

x86 平台实现一个原子加法操作

1&#xff0c;先上代码 #include <iostream> #include <omp.h>int atomicAdd(int* ptr, int value) {int result;asm volatile("lock xaddl %0, %1\n": "r" (result), "m" (*ptr): "0" (value), "m" (*ptr): &…

程序猿大战Python——Python与MySQL交互三

SQL注入 目标&#xff1a;了解什么是SQL注入&#xff1f; SQL注入指的是&#xff1a;恶意篡改或注入SQL条件。 当开发者的数据条件若被恶意篡改&#xff0c;那就达不到预期的查询效果。 为了了解SQL注入是怎么回事&#xff1f;通过一个案例来分析。 例如&#xff0c;使用命令…

综合布线实训室建设可行性报告

1、 建设综合布线实训室的目的和意义 1.1 响应国家职业教育政策 在国家对职业教育的高度重视和政策支持下&#xff0c;综合布线实训室的建设不仅是对国家教育方针的积极响应&#xff0c;也是对技术教育改革的有力推动。通过这一平台&#xff0c;我们旨在培育出一批具有强烈实…

ChatGPT智能对话绘画系统 带完整的安装源代码包以及搭建教程

系统概述 ChatGPT 智能对话绘画系统是一款集智能语言处理和绘画创作于一体的综合性系统。它利用了深度学习和自然语言处理技术&#xff0c;能够理解用户的意图和需求&#xff0c;并通过与用户的交互&#xff0c;生成富有创意的绘画作品。该系统的核心是一个强大的人工智能模型…

高考后的抉择:专业优先还是学校优先?

随着2024年高考的帷幕落下&#xff0c;高考生们面临的一个重要抉择再度浮上心头&#xff1a;在分数受限的情况下&#xff0c;是选择一个心仪的专业&#xff0c;还是选择一个知名度更高的学校&#xff1f;这是一个困扰了众多考生和家长的长期难题。在这个关键的时刻&#xff0c;…

“一团乱麻”到底什么是烟雾病呢?

当我们听到“烟雾病”这个名字时&#xff0c;可能会联想到与吸烟有关的疾病&#xff0c;但实际上&#xff0c;这是一种与吸烟毫无关系的罕见脑血管疾病。它的名字来源于在脑血管造影中&#xff0c;病变的血管网看起来像一团乱麻&#xff0c;又似吸烟时吐出的烟雾。 烟雾病&…

uniapp, ‍[⁠TypeError⁠]‍ “Failed to fetch dynamically imported module“ 报错解决思路

文章目录 1. 背景2. 报错3. 解决思路4. 思考参考1. 背景 最近基于uniapp开发一款设备参数调试的APP软件,在使用第三方插件的过程中,出现下面的报错。 2. 报错 [plugin:vite:import-analysis] Cannot find module ‘D:/leaning/uniapp/demo/jk-uts-udp示例/uni_modules/uts-…

基于FreeRTOS+STM32CubeMX+LCD1602+MCP3001(SPI接口)的ADC转换器Proteus仿真

一、仿真原理图: 二、仿真效果: 三、STM32CubeMX配置: 1)、USART配置: 2)、SPI配置: 四、软件部分: 1)、时钟、SPI、USART初始化部分: /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RC…

Docker-Compose一键部署项目

Docker-Compose一键部署项目 目录 Docker-Compose一键部署项目介绍部署Django项目项目目录结构 docker-compose.ymlnginx的default.conf文件后端Dockerfile文件mysql.env一键部署DNS域名解析引起的跨域问题 介绍 Docker Compose 是一个用于定义和运行多容器 Docker 应用程序的…

网络世界的“握手”与“告别”:揭秘TCP的三次握手与四次挥手

在网络世界中&#xff0c;数据的传输就像是一场精心编排的舞蹈&#xff0c;而TCP&#xff08;Transmission Control Protocol&#xff0c;传输控制协议&#xff09;则是这场舞蹈的指挥家。它确保数据在网络中的传输既稳定又可靠。那么&#xff0c;在这背后&#xff0c;TCP是如何…

红黑树原理 部分模拟实现

1.红黑树的概念及性质 红黑树的概念 红黑树&#xff0c;是一种二叉搜索树&#xff0c;但在每个结点上增加一个存储位表示结点的颜色&#xff0c;可以是Red或Black。 通过对任何一条从根到叶子的路径上各个结点着色方式的限制&#xff0c;红黑树确保没有一条路径会比其他路径长出…

Redis和PHP的Bitmap于二进制串的相互转换

Redis和PHP的Bitmap于二进制串的相互转换 场景 错题集的存储&#xff0c;需要有正确的题号id集合&#xff0c;错误的题号id集合&#xff0c;两者并集后在全量题的集合中取反就是未答题号id 选型 基于场景的数据结构设计&#xff0c;有试过列表等&#xff0c;测试结果&#xff1…