围棋棋盘的图像(识别)240801

news2024/12/23 10:39:07

识别:

import tensorflow as tf
import numpy as np
from tensorflow.keras import layers, models
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.image import load_img, img_to_array

# 加载并预处理图像
def load_and_preprocess_image(image_path):
    img = load_img(image_path, color_mode='grayscale', target_size=(6, 6))
    img_array = img_to_array(img)
    img_array = img_array.astype('float32') / 255.0  # 归一化到0-1之间
    return img_array

# 标签
labels = [
    [[0, 0, 0, 0, 0, 0],
     [0, 1, 2, 0, 0, 0],
     [2, 1, 0, 0, 0, 0],
     [0, 0, 0, 2, 1, 0],
     [0, 0, 0, 1, 2, 0],
     [0, 0, 0, 0, 0, 0]],

    [[0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0]],

    [[0, 0, 0, 0, 0, 0],
     [0, 1, 0, 0, 0, 0],
     [0, 1, 0, 0, 0, 0],
     [0, 0, 0, 0, 1, 0],
     [0, 0, 0, 1, 0, 0],
     [0, 0, 0, 0, 0, 0]],

    [[0, 0, 0, 0, 0, 0],
     [0, 0, 2, 0, 0, 0],
     [2, 0, 0, 0, 0, 0],
     [0, 0, 0, 2, 0, 0],
     [0, 0, 0, 0, 2, 0],
     [0, 0, 0, 0, 0, 0]],
]

# 转换标签为 one-hot 编码
labels = np.array([to_categorical(label, num_classes=3) for label in labels])

# 加载图像数据
image_paths = ['d:/weiqi/wq001.png', 'd:/weiqi/wq002.png', 'd:/weiqi/wq003.png', 'd:/weiqi/wq004.png']
images = np.array([load_and_preprocess_image(path) for path in image_paths])

# 构建CNN模型
model = models.Sequential([
    layers.Conv2D(32, (3, 3), activation='relu', padding='same', input_shape=(6, 6, 1)),
    layers.Flatten(),
    layers.Dense(128, activation='relu'),
    layers.Dense(6 * 6 * 3, activation='softmax'),  # 输出18个分类
])

model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

# 将标签 reshape 成模型所需的形状
labels = labels.reshape((labels.shape[0], 6 * 6 * 3))

# 训练模型
model.fit(images, labels, epochs=10)

# 测试模型
test_image = load_and_preprocess_image('d:/weiqi/wq005.png')
test_image = np.expand_dims(test_image, axis=0)  # 添加一个批次维度
prediction = model.predict(test_image)
prediction = prediction.reshape((6, 6, 3))
predicted_labels = np.argmax(prediction, axis=2)

print("预测标签:")
print(predicted_labels)



起点python:
 

import numpy as np
import matplotlib.pyplot as plt

def draw_circle(img, center, radius, value, fill=False):
    """在图像上绘制一个圆"""
    a, b = center
    for x in range(center[0] - radius, center[0] + radius):
        for y in range(center[1] - radius, center[1] + radius):
            if (x - a)**2 + (y - b)**2 <= radius**2:
                if fill or (x - a)**2 + (y - b)**2 >= (radius-1)**2:
                    img[x, y] = value
                else:
                    img[x,y]=0

def generate_go_board(N, M, board_size=20):
    # 计算图像的尺寸
    img_size = (N * board_size, M * board_size)
    img = np.zeros((img_size[0], img_size[1]), dtype=int)
    
    # 绘制网格
    for i in range(N):
        for j in range(M):
            x = i * board_size + board_size // 2
            x1=board_size // 2
            x2=x-x1
            y = j * board_size + board_size // 2
            y1=board_size//2
            y2=y-y1
            img[x, y1:(y+1)] = 1  # 横线
            img[x1:x, y] = 1  # 竖线
    
    # 添加黑子(实心圆)和白子(空心圆)
    black_positions = [ (1,1),(2, 1), (4, 3), (3,4)]  # 黑子位置
    white_positions = [(2,0),(1, 2), (3, 3), (4,4)]  # 白子位置
    
    
    for pos in black_positions:
        center = (pos[0] * board_size + board_size // 2, pos[1] * board_size + board_size // 2)
        draw_circle(img, center, board_size // 3, 1, fill=True)
    
    for pos in white_positions:
        center = (pos[0] * board_size + board_size // 2, pos[1] * board_size + board_size // 2)
        draw_circle(img, center, board_size // 3, 1, fill=False)
    
    return img

# 测试生成 4列5行 的围棋棋盘
M = 5
N = 6
board = generate_go_board(N, M)

# 显示结果
plt.imshow(board, cmap='gray')
plt.axis('equal')
plt.show()

# 打印结果
for row in board:
#    print("\t".join(map(str, row)))
    print("".join(map(str, row)))

生成图像:

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000001111111000000000000011111110000000000000000100000000000000000001000000000
0000000000100000000000000011111111100000000000110010011000000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001100010001100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001100010001100000000000000100000000000000000001000000000
0000000000100000000000000011111111100000000000110010011000000000000000100000000000000000001000000000
0000000000100000000000000001111111000000000000011111110000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000111111100000000000001111111000000000000000010000000000000000000100000000000000000001000000000
0000001100100110000000000011111111100000000000000010000000000000000000100000000000000000001000000000
0000011000100011000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000110000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000011000100011000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000001100100110000000000011111111100000000000000010000000000000000000100000000000000000001000000000
0000000111111100000000000001111111000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000001100100110000000000011111111100000
0000000000100000000000000000001000000000000000000010000000000000011000100011000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000011000100011000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000001100100110000000000011111111100000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000001111111110000000000011001001100000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000110001000110000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000110001000110000
0000000000100000000000000000001000000000000000000010000000000000001111111110000000000011001001100000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Click to add a cell.
import numpy as np
import tensorflow as tf

# 给定的棋盘图像数据
import numpy as np

X_train = np.array([
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0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
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
])


# 对应的标签 (将围棋位置编码)
y_train = np.array([
    [0, 0, 0, 0],
    [0, 0, 1, 0],
    [0, 2, 0, 0],
    [0, 1, 2, 0],
    [0, 0, 0, 0]
])

# 转换输入数据的形状以匹配模型要求
X_train = X_train.reshape((-1, 40, 50, 1))

# 输出标签需要转换为独热编码
y_train = tf.keras.utils.to_categorical(y_train, num_classes=20)

# 打印 X_train 和 y_train 的形状
print(X_train.shape)
print(y_train.shape)

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux升级lib64中的libc.so.6导致所有命令失效

ls: relocation error: libpthread.so.0: symbol __libc_dl_error_tsd, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference 升级Glibc后出现所有shell命令都不可用 # systemctl status systemctl: relocation error: /lib64/libpthread.so.0: sy…

为视觉语言多模态模型进行偏好优化

训练模型使得它能够理解并预测人类偏好是一项比较复杂的任务。诸如 SFT (Supervised finetuning) 的传统的方法一般都需要耗费较大成本&#xff0c;因为这些算法需要对数据打上特定的标签。而偏好优化 (Preference Optimization) 作为一种替代选项&#xff0c;通常可以简化这一…

【10-21】设计原则

目录 一.开闭原则 二.里氏代换原则 三.依赖倒转原则 四.接口隔离原则 五.迪米特法则 六.合成复用原则 前言&#xff1a; 在软件开发中&#xff0c;为了提高软件系统的可维护性和可复用性&#xff0c;增加软件的可拓展性和灵活性&#xff0c;程序员要尽量根据6条原则来开发…

关于WebSocket必知必会的知识点

什么是WebSocket WebSocket是一种网络传输协议&#xff0c;可以在单个TCP连接上进行全双工通信&#xff0c;位于OSI模型的应用层。 WebSocket使得客户端和服务器之间的数据交换变得更加简单&#xff0c;服务器可以主动向客户端发送消息。在WebSocket API中&#xff0c;浏览器和…

20240820让飞凌的OK3588-C的核心板在Linux R4下挂载1TB的NTFS格式的TF卡

fdisk -l df -h df -t df -T mount 20240820让飞凌的OK3588-C的核心板在Linux R4下挂载1TB的NTFS格式的TF卡 2024/8/20 18:03 【默认挂载到/run/media/mmcblk1&#xff0c;不用任何操作&#xff01;】 插入1TB的TF卡之后的dmesg信息&#xff1a; [ 876.551728] fdee0000.hdmi…

pandans读写分析csv文件

1.什么是pandans Pandas 是一个强大的 Python 库&#xff0c;主要用于数据处理和数据分析。它为 Python 提供了高效的数据结构和数据分析工具&#xff0c;使得数据处理变得更加简单和直观。 2.什么事csv文件 CSV 文件&#xff08;Comma-Separated Values&#xff0c;逗号分隔值…

点亮宇宙的温暖之光 —— COSMOSPANDA星际熊猫“寞”降临!

在这个科技日新月异的时代&#xff0c;我们往往在追求进步的同时&#xff0c;忽略了心中那份最真挚的情感与温暖。但今天&#xff0c;让我们共同迎接一位来自宇宙深处的温暖使者——COSMOSPANDA星际熊猫“寞”&#xff0c;它将用独特的方式&#xff0c;连接过去与未来&#xff…

3:2比例的程序员专业显示器,效率提升显著,摸鱼时间又多了

对于我们程序员来说&#xff0c;显示器的重要性不言而喻&#xff0c;作为我们与代码交流的直接工具&#xff0c;他影响着我们的工作效率、舒适度和整体编程体验。我在家用的是自己笔记本的屏幕&#xff0c;简单写写代码还行&#xff0c;涉及到多任务协同或者大代码量开发就有点…

Linux 下安装miniconda(少走弯路)

Miniconda 和 Conda 都是用于管理 Python&#xff08;及其他语言&#xff09;环境和包的工具。 conda对于我来说是太臃肿了&#xff0c;很多的包我不会使用&#xff0c;所以选择安装miniconda是一个较好的选择。 下面是linux安装miniconda的实际操作。 在以下的网站&#xf…

复现 LET-NET

摘要 稀疏光流法是计算机视觉中的一项基本任务。然而&#xff0c;它依赖于恒定的假设限制了其在高动态范围&#xff08;HDR&#xff09;场景中的适用性。在本研究中&#xff0c;我们提出了一种新的方法&#xff0c;旨在通过学习一个对光照变化具有鲁棒性的特征映射来超越图像的…

LabVIEW轨距实时动态检测系统

轨距实时动态检测系统解决铁路轨距不平顺现象&#xff0c;提高铁路运行安全性。系统利用高精度的激光位移传感器与数据同步采集技术&#xff0c;结合LabVIEW软件进行数据处理&#xff0c;有效提高了轨距检测的准确性与效率。 项目背景 随着铁路运输业的快速发展&#xff0c;轨…

速度+耐力,希迪智驾引领中国商用车自动驾驶发展

作者 | 魏启扬 来源 | 洞见新研社 资本市场对自动驾驶的投资热情依然不减。 不久前&#xff0c;科技巨头Alphabet重申了对自动驾驶未来的承诺&#xff0c;并表示将向其自动驾驶子公司Waymo投资50亿美元&#xff0c;分多年进行。 更早一点的5月份&#xff0c;孙正义旗下的…

如何使用 JavaScript 动态创建下拉框?

在现代 Web 开发中&#xff0c;动态生成页面元素是一个常见的需求&#xff0c;比如在用户选择某个选项后&#xff0c;根据选择的内容动态生成新的下拉框。今天&#xff0c;我们来聊一聊如何使用 JavaScript 动态创建一个带选项的下拉框&#xff0c;并用一个具体的场景带大家进入…

第十九讲 python中的异常本质-异常定位-异常解决思路

目录 1.异常是什么&#xff1f; 2.异常机制的本质 2.1 本质 2.2 异常对象 2.3 抛出异常 2.4 捕捉异常 2.5 最终处理 3.异常的解决思路 3.1 异常定位 3.2 异常解决 1.异常是什么&#xff1f; 异常是指程序在运行时发生的错误或不正常情况。 工作中&#xff0c;程序遇到的情况不…

数据结构中的双向链表

1.链表的分类 链表的结构非常多样&#xff0c;以下情况组合起来就是8种&#xff08;2x2x2&#xff09;链表结构&#xff1a; 在带头链表中&#xff0c;除了头结点&#xff0c;其他结点均存储有效的数据。 头结点是占位子的&#xff0c;也叫做“哨兵位”。head结点就是头结点。…

【实战场景】如何优雅实现分页

【实战场景】如何优雅实现分页 开篇词&#xff1a;干货篇&#xff1a;1.添加PageHelper依赖2.添加PageHelper配置3.使用 PageHelper4.自定义Pageable注解 总结&#xff1a;1.执行查询2.处理分页结果3.注意事项 我是杰叔叔&#xff0c;一名沪漂的码农&#xff0c;下期再会&#…

代码随想录算法训练营day49 | 42. 接雨水、84.柱状图中最大的矩形

碎碎念&#xff1a; 参考&#xff1a;代码随想录 42. 接雨水 题目链接 42. 接雨水 思想 如图可以按照列来计算&#xff0c;这样宽度一定是1&#xff0c;只需要计算每一列的雨水的高度接口。而每一列的雨水高度取决于该列左侧最高的主子和右侧最高柱子中最矮的那个柱子的高度…

如何使用Java SpringBoot+Vue搭建半成品配菜平台,实现家庭烹饪新体验

✍✍计算机毕业编程指导师 ⭐⭐个人介绍&#xff1a;自己非常喜欢研究技术问题&#xff01;专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目&#xff1a;有源码或者技术上的问题欢迎在评论区一起讨论交流&#xff01; ⚡⚡ Java、…

用Python编写一个超级玛丽游戏|附源码

​ 编写一个超级玛丽游戏是一个复杂的任务&#xff0c;涉及到多个方面的编程知识和技巧。下面&#xff0c;我将详细讲解如何用Python编写一个简化版的超级玛丽游戏&#xff0c;包括所需的库、游戏逻辑、角色控制、关卡设计、碰撞检测等方面。 所需库 为了编写这个游戏&#…

猫咪去浮毛能一劳永逸吗?手动不行宠物空气净化器是真能做到

现在啊&#xff0c;越来越多的家庭选择养宠物来增添生活乐趣。但宠物带来的快乐背后&#xff0c;也有那么点“小困扰”&#xff1a;下班回家&#xff0c;迎接你的可能是满屋子的“特殊香味”和无处不在的毛发。这样的环境&#xff0c;真的不会对我们的健康产生不良影响吗&#…