Python经典游戏 唤醒你童年记忆

这些游戏你玩过几个?

    • 1.贪吃蛇
    • 2.吃豆人
    • 3.加农炮
    • 4.四子棋
    • 5. Fly Bird
    • <font color = #f3704ab>6.记忆:数字对拼图游戏(欢迎挑战!用时:2min)
    • 7.乒乓球
    • 8.上课划水必备-井字游戏(我敢说100%的人都玩过)
    • 9.将数字滑动到位的拼图游戏
    • 10.迷宫(我己经晕了,你们来)
  • 获取更多

1.贪吃蛇

👉游戏规则:使用方向键控制蛇去吃球。每吃一次球,蛇身就长出一格。吃到自己或者出界游戏结束。

from random import randrange
from turtle import *
from freegames import square, vectorfood = vector(0, 0)
snake = [vector(10, 0)]
aim = vector(0, -10)def change(x, y):"""Change snake direction."""aim.x = xaim.y = ydef inside(head):"""Return True if head inside boundaries."""return -200 < head.x < 190 and -200 < head.y < 190def move():"""Move snake forward one segment."""head = snake[-1].copy()head.move(aim)if not inside(head) or head in snake:square(head.x, head.y, 9, 'red')update()returnsnake.append(head)if head == food:print('Snake:', len(snake))food.x = randrange(-15, 15) * 10food.y = randrange(-15, 15) * 10else:snake.pop(0)clear()for body in snake:square(body.x, body.y, 9, 'black')square(food.x, food.y, 9, 'green')update()ontimer(move, 100)setup(420, 420, 370, 0)
hideturtle()
tracer(False)
listen()
onkey(lambda: change(10, 0), 'Right')
onkey(lambda: change(-10, 0), 'Left')
onkey(lambda: change(0, 10), 'Up')
onkey(lambda: change(0, -10), 'Down')
move()
done()

游戏演示:

在这里插入图片描述

2.吃豆人

👉游戏规则:用箭头导航控制黄色吃豆人吃掉所有白色食物,若被红色的鬼魂抓住,游戏结束。

from random import choice
from turtle import *from freegames import floor, vectorstate = {'score': 0}
path = Turtle(visible=False)
writer = Turtle(visible=False)
aim = vector(5, 0)
pacman = vector(-40, -80)
ghosts = [[vector(-180, 160), vector(5, 0)],[vector(-180, -160), vector(0, 5)],[vector(100, 160), vector(0, -5)],[vector(100, -160), vector(-5, 0)],
]
# fmt: off
tiles = [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, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0,0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0,0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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,
]
# fmt: ondef square(x, y):"""Draw square using path at (x, y)."""path.up()path.goto(x, y)path.down()path.begin_fill()for count in range(4):path.forward(20)path.left(90)path.end_fill()def offset(point):"""Return offset of point in tiles."""x = (floor(point.x, 20) + 200) / 20y = (180 - floor(point.y, 20)) / 20index = int(x + y * 20)return indexdef valid(point):"""Return True if point is valid in tiles."""index = offset(point)if tiles[index] == 0:return Falseindex = offset(point + 19)if tiles[index] == 0:return Falsereturn point.x % 20 == 0 or point.y % 20 == 0def world():"""Draw world using path."""bgcolor('black')path.color('blue')for index in range(len(tiles)):tile = tiles[index]if tile > 0:x = (index % 20) * 20 - 200y = 180 - (index // 20) * 20square(x, y)if tile == 1:path.up()path.goto(x + 10, y + 10)path.dot(2, 'white')def move():"""Move pacman and all ghosts."""writer.undo()writer.write(state['score'])clear()if valid(pacman + aim):pacman.move(aim)index = offset(pacman)if tiles[index] == 1:tiles[index] = 2state['score'] += 1x = (index % 20) * 20 - 200y = 180 - (index // 20) * 20square(x, y)up()goto(pacman.x + 10, pacman.y + 10)dot(20, 'yellow')for point, course in ghosts:if valid(point + course):point.move(course)else:options = [vector(5, 0),vector(-5, 0),vector(0, 5),vector(0, -5),]plan = choice(options)course.x = plan.xcourse.y = plan.yup()goto(point.x + 10, point.y + 10)dot(20, 'red')update()for point, course in ghosts:if abs(pacman - point) < 20:returnontimer(move, 100)def change(x, y):"""Change pacman aim if valid."""if valid(pacman + vector(x, y)):aim.x = xaim.y = ysetup(420, 420, 370, 0)
hideturtle()
tracer(False)
writer.goto(160, 160)
writer.color('white')
writer.write(state['score'])
listen()
onkey(lambda: change(5, 0), 'Right')
onkey(lambda: change(-5, 0), 'Left')
onkey(lambda: change(0, 5), 'Up')
onkey(lambda: change(0, -5), 'Down')
world()
move()
done()

游戏演示:

在这里插入图片描述

3.加农炮

👉游戏规则:点击屏幕发射炮弹。炮弹在它的路径上弹出蓝色气球。在气球穿过屏幕之前把它们全部弹出。

from random import randrange
from turtle import *from freegames import vectorball = vector(-200, -200)
speed = vector(0, 0)
targets = []def tap(x, y):"""Respond to screen tap."""if not inside(ball):ball.x = -199ball.y = -199speed.x = (x + 200) / 25speed.y = (y + 200) / 25def inside(xy):"""Return True if xy within screen."""return -200 < xy.x < 200 and -200 < xy.y < 200def draw():"""Draw ball and targets."""clear()for target in targets:goto(target.x, target.y)dot(20, 'blue')if inside(ball):goto(ball.x, ball.y)dot(6, 'red')update()def move():"""Move ball and targets."""if randrange(40) == 0:y = randrange(-150, 150)target = vector(200, y)targets.append(target)for target in targets:target.x -= 0.5if inside(ball):speed.y -= 0.35ball.move(speed)dupe = targets.copy()targets.clear()for target in dupe:if abs(target - ball) > 13:targets.append(target)draw()for target in targets:if not inside(target):returnontimer(move, 50)setup(420, 420, 370, 0)
hideturtle()
up()
tracer(False)
onscreenclick(tap)
move()
done()

游戏演示:

在这里插入图片描述

4.四子棋

👉 游戏规则:单击行可放置光盘。第一个垂直、水平或对角连接四张光盘的玩家获胜。

from turtle import *from freegames import lineturns = {'red': 'yellow', 'yellow': 'red'}
state = {'player': 'yellow', 'rows': [0] * 8}def grid():"""Draw Connect Four grid."""bgcolor('light blue')for x in range(-150, 200, 50):line(x, -200, x, 200)for x in range(-175, 200, 50):for y in range(-175, 200, 50):up()goto(x, y)dot(40, 'white')update()def tap(x, y):"""Draw red or yellow circle in tapped row."""player = state['player']rows = state['rows']row = int((x + 200) // 50)count = rows[row]x = ((x + 200) // 50) * 50 - 200 + 25y = count * 50 - 200 + 25up()goto(x, y)dot(40, player)update()rows[row] = count + 1state['player'] = turns[player]setup(420, 420, 370, 0)
hideturtle()
tracer(False)
grid()
onscreenclick(tap)
done()

游戏演示:

在这里插入图片描述

5. Fly Bird

👉 游戏规则:点击屏幕来拍打鸟的翅膀。飞过屏幕被黑色乌鸦碰到,游戏结束。

from random import *
from turtle import *from freegames import vectorbird = vector(0, 0)
balls = []def tap(x, y):"""Move bird up in response to screen tap."""up = vector(0, 30)bird.move(up)def inside(point):"""Return True if point on screen."""return -200 < point.x < 200 and -200 < point.y < 200def draw(alive):"""Draw screen objects."""clear()goto(bird.x, bird.y)if alive:dot(10, 'green')else:dot(10, 'red')for ball in balls:goto(ball.x, ball.y)dot(20, 'black')update()def move():"""Update object positions."""bird.y -= 5for ball in balls:ball.x -= 3if randrange(10) == 0:y = randrange(-199, 199)ball = vector(199, y)balls.append(ball)while len(balls) > 0 and not inside(balls[0]):balls.pop(0)if not inside(bird):draw(False)returnfor ball in balls:if abs(ball - bird) < 15:draw(False)returndraw(True)ontimer(move, 50)setup(420, 420, 370, 0)
hideturtle()
up()
tracer(False)
onscreenclick(tap)
move()
done()

游戏演示:

在这里插入图片描述

6.记忆:数字对拼图游戏(欢迎挑战!用时:2min)

👉游戏规则:单击方格用于显示数字。匹配两个数字,方格将显示从而显示图像。

from random import *
from turtle import *from freegames import pathcar = path('car.gif')
tiles = list(range(32)) * 2
state = {'mark': None}
hide = [True] * 64def square(x, y):"""Draw white square with black outline at (x, y)."""up()goto(x, y)down()color('black', 'white')begin_fill()for count in range(4):forward(50)left(90)end_fill()def index(x, y):"""Convert (x, y) coordinates to tiles index."""return int((x + 200) // 50 + ((y + 200) // 50) * 8)def xy(count):"""Convert tiles count to (x, y) coordinates."""return (count % 8) * 50 - 200, (count // 8) * 50 - 200def tap(x, y):"""Update mark and hidden tiles based on tap."""spot = index(x, y)mark = state['mark']if mark is None or mark == spot or tiles[mark] != tiles[spot]:state['mark'] = spotelse:hide[spot] = Falsehide[mark] = Falsestate['mark'] = Nonedef draw():"""Draw image and tiles."""clear()goto(0, 0)shape(car)stamp()for count in range(64):if hide[count]:x, y = xy(count)square(x, y)mark = state['mark']if mark is not None and hide[mark]:x, y = xy(mark)up()goto(x + 2, y)color('black')write(tiles[mark], font=('Arial', 30, 'normal'))update()ontimer(draw, 100)shuffle(tiles)
setup(420, 420, 370, 0)
addshape(car)
hideturtle()
tracer(False)
onscreenclick(tap)
draw()
done()

游戏演示:

在这里插入图片描述

7.乒乓球

👉游戏规则:用键盘上下移动划桨,谁先丢失球,谁输!(左ws上下,右ik上下)

from random import choice, random
from turtle import *from freegames import vectordef value():"""Randomly generate value between (-5, -3) or (3, 5)."""return (3 + random() * 2) * choice([1, -1])ball = vector(0, 0)
aim = vector(value(), value())
state = {1: 0, 2: 0}def move(player, change):"""Move player position by change."""state[player] += changedef rectangle(x, y, width, height):"""Draw rectangle at (x, y) with given width and height."""up()goto(x, y)down()begin_fill()for count in range(2):forward(width)left(90)forward(height)left(90)end_fill()def draw():"""Draw game and move pong ball."""clear()rectangle(-200, state[1], 10, 50)rectangle(190, state[2], 10, 50)ball.move(aim)x = ball.xy = ball.yup()goto(x, y)dot(10)update()if y < -200 or y > 200:aim.y = -aim.yif x < -185:low = state[1]high = state[1] + 50if low <= y <= high:aim.x = -aim.xelse:returnif x > 185:low = state[2]high = state[2] + 50if low <= y <= high:aim.x = -aim.xelse:returnontimer(draw, 50)setup(420, 420, 370, 0)
hideturtle()
tracer(False)
listen()
onkey(lambda: move(1, 20), 'w')
onkey(lambda: move(1, -20), 's')
onkey(lambda: move(2, 20), 'i')
onkey(lambda: move(2, -20), 'k')
draw()
done()

游戏演示:

在这里插入图片描述

8.上课划水必备-井字游戏(我敢说100%的人都玩过)

👉游戏规则:点击屏幕放置一个X或O。连续连接三个,就赢了!

from turtle import *from freegames import linedef grid():"""Draw tic-tac-toe grid."""line(-67, 200, -67, -200)line(67, 200, 67, -200)line(-200, -67, 200, -67)line(-200, 67, 200, 67)def drawx(x, y):"""Draw X player."""line(x, y, x + 133, y + 133)line(x, y + 133, x + 133, y)def drawo(x, y):"""Draw O player."""up()goto(x + 67, y + 5)down()circle(62)def floor(value):"""Round value down to grid with square size 133."""return ((value + 200) // 133) * 133 - 200state = {'player': 0}
players = [drawx, drawo]def tap(x, y):"""Draw X or O in tapped square."""x = floor(x)y = floor(y)player = state['player']draw = players[player]draw(x, y)update()state['player'] = not playersetup(420, 420, 370, 0)
hideturtle()
tracer(False)
grid()
update()
onscreenclick(tap)
done()

游戏演示:

在这里插入图片描述

9.将数字滑动到位的拼图游戏

👉 游戏规则:单击靠近空正方形的方格以交换位置。将所有数字从左到右按顺序排列。

from random import *
from turtle import *from freegames import floor, vectortiles = {}
neighbors = [vector(100, 0),vector(-100, 0),vector(0, 100),vector(0, -100),
]def load():"""Load tiles and scramble."""count = 1for y in range(-200, 200, 100):for x in range(-200, 200, 100):mark = vector(x, y)tiles[mark] = countcount += 1tiles[mark] = Nonefor count in range(1000):neighbor = choice(neighbors)spot = mark + neighborif spot in tiles:number = tiles[spot]tiles[spot] = Nonetiles[mark] = numbermark = spotdef square(mark, number):"""Draw white square with black outline and number."""up()goto(mark.x, mark.y)down()color('black', 'white')begin_fill()for count in range(4):forward(99)left(90)end_fill()if number is None:returnelif number < 10:forward(20)write(number, font=('Arial', 60, 'normal'))def tap(x, y):"""Swap tile and empty square."""x = floor(x, 100)y = floor(y, 100)mark = vector(x, y)for neighbor in neighbors:spot = mark + neighborif spot in tiles and tiles[spot] is None:number = tiles[mark]tiles[spot] = numbersquare(spot, number)tiles[mark] = Nonesquare(mark, None)def draw():"""Draw all tiles."""for mark in tiles:square(mark, tiles[mark])update()setup(420, 420, 370, 0)
hideturtle()
tracer(False)
load()
draw()
onscreenclick(tap)
done()

游戏演示:

在这里插入图片描述

10.迷宫(我己经晕了,你们来)

👉游戏规则:从一边移到另一边。轻触屏幕可跟踪从一侧到另一侧的路径。

from random import random
from turtle import *from freegames import linedef draw():"""Draw maze."""color('black')width(5)for x in range(-200, 200, 40):for y in range(-200, 200, 40):if random() > 0.5:line(x, y, x + 40, y + 40)else:line(x, y + 40, x + 40, y)update()def tap(x, y):"""Draw line and dot for screen tap."""if abs(x) > 198 or abs(y) > 198:up()else:down()width(2)color('red')goto(x, y)dot(4)setup(420, 420, 370, 0)
hideturtle()
tracer(False)
draw()
onscreenclick(tap)
done()

游戏演示:

在这里插入图片描述

获取更多

更多好玩小游戏,可以直接点击获取哦!!

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

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

相关文章

桥接模式-举例

概叙&#xff1a;桥接模式用一种巧妙的方式处理多层继承存在的问题&#xff0c; 用抽象关联取代了传统的多层继承&#xff0c; 将类之间的静态继承关系转换为动态的对象组合关系&#xff0c; 使得系统更加灵活&#xff0c;并易于扩展&#xff0c; 同时有效控制了系统中类的个数…

硅像素传感器文献调研(三)

写在前面&#xff1a; 引言&#xff1a;也是先总结前人的研究结果&#xff0c;重点论述其不足之处。 和该方向联系不大&#xff0c;但还是有值得学习的地方。逻辑很清晰&#xff0c;易读性很好。 1991年—场板半阻层 使用场板和半电阻层的高压平面器件 0.摘要 提出了一种…

基于JAVA的瑜伽馆管理系统 开源项目

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 数据中心模块2.2 瑜伽课程模块2.3 课程预约模块2.4 系统公告模块2.5 课程评价模块2.6 瑜伽器械模块 三、系统设计3.1 实体类设计3.1.1 瑜伽课程3.1.2 瑜伽课程预约3.1.3 系统公告3.1.4 瑜伽课程评价 3.2 数据库设计3.2.…

在微服务中如何实现全链路的金丝雀发布?

目录 1. 什么金丝雀发布&#xff1f;它有什么用&#xff1f; 2.如何实现全链路的金丝雀发布 2.1 负载均衡模块 2.2 网关模块 2.3 服务模块 2.3.1 注册为灰色服务实例 2.3.2 设置负载均衡器 2.3.3 传递灰度发布标签 2.4 其他代码 2.4.1 其他业务代码 2.4.2 pom.xml 关…

Linux下MQTT环境的简单应用及搭建——之Mosquitto

文章目录 前言一、ubuntu搭建mqtt服务器 | 概要二、整体架构流程 | 技术实现细节1、下载源码2、安装Mosquitto3、解压并修改配置文件4、关于Mosquitto常见的一些操作指令5、启动mosquitto6、测试mosquitto测试1&#xff1a;Linux多终端交互测试测试2&#xff1a;Linux与Windows…

中职网络安全Web2003-2——Web渗透测试

需要环境或换&#xff0c;有问题可以私信我或加Q 1.通过URL访问http://靶机IP/1&#xff0c;对该页面进行渗透测试&#xff0c;将完成后返回的结果内容作为Flag值提交&#xff1b; FLAGflag{htmlcode} 2.通过URL访问http://靶机IP/2&#xff0c;对该页面进行渗透测试&#xff…

【C#】深拷贝和浅拷贝

文章目录 深拷贝和浅拷贝的定义深拷贝&#xff08;Deep Copy&#xff09;浅拷贝&#xff08;Shallow Copy&#xff09; 深拷贝和浅拷贝的定义 深拷贝&#xff08;Deep Copy&#xff09;和浅拷贝&#xff08;Shallow Copy&#xff09;是在复制对象时涉及的两个不同概念 深拷贝…

硅像素传感器文献调研(四)

写在前面&#xff1a; 好喜欢这种短论文哈哈哈哈哈 感觉这篇文献已经提到了保护环的概念啊&#xff0c;只不过叫的是&#xff1a;场限制环。 1986——高压功率器件场终端横向掺杂的变化 0.摘要 对于高压平面结提出了一个简单的新概念。通过在氧化物掩模中的小开口和随后的驱…

响应式绑定<a-textarea>的内容

项目中的 <a-textarea>组件需要自动填入下方数据表的物品名称数量单位&#xff0c;效果如下&#xff1a; 尝试 <a-textarea>{{插值}}</a-textarea>&#xff0c;实现不了&#xff0c;问ai得知需要使用v-decorator 指令的initialValue 属性 问&#xff1a; 如何…

自己动手写编译器:算术表达式的语法分析实例和代码实现

在编译原理中&#xff0c;语法解析可能是最抽象和难以理解的部分&#xff0c;初学者很容易在这里卡壳。学习抽象知识的最好方法就是在初期先看大量具体实例&#xff0c;获得足够深厚的感性认识后&#xff0c;我们再对感性认知进行推理和抽象从而获得更高级的理性认知&#xff0…

VMware之FTP的简介以及搭建使用计算机端口的介绍

&#x1f3ac; 艳艳耶✌️&#xff1a;个人主页 &#x1f525; 个人专栏 &#xff1a;《产品经理如何画泳道图&流程图》 ⛺️ 越努力 &#xff0c;越幸运 目录 一、FTP介绍 1、什么是FTP&#xff1a; 2、FTP适用于以下情况和应用场景&#xff1a; 3、winServer2012搭…

最长连续子序列 - 华为OD统一考试

OD统一考试(B卷) 分值: 100分 题解: Java / Python / C++ 题目描述 有N个正整数组成的一个序列。给定整数sum,求长度最长的连续子序列,使他们的和等于sum,返回此子序列的长度, 如果没有满足要求的序列,返回-1。 输入描述 第一行输入是:N个正整数组成的一个序列。…

VBA启动问题:vbe6ext.olb不能被加载

1、拷贝文件&#xff1a; 从&#xff1a; C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB 到&#xff1a; C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\VBA\VBA7.1\VBE…

虹科方案丨L2进阶L3,数据采集如何助力自动驾驶

来源&#xff1a;康谋自动驾驶 虹科方案丨L2进阶L3&#xff0c;数据采集如何助力自动驾驶 原文链接&#xff1a;https://mp.weixin.qq.com/s/qhWy11x_-b5VmBt86r4OdQ 欢迎关注虹科&#xff0c;为您提供最新资讯&#xff01; 12月14日&#xff0c;宝马集团宣布&#xff0c;搭载…

【2024最新版】我用python代码带你看最绚烂的烟花,浪漫永不过时!

2024年就快要到了&#xff0c;提前用python代码给自己做一个烟花秀庆祝一下。本次介绍的python实例是实现一个简易的烟花秀。 一、步骤分析 总的来说&#xff0c;要实现烟花秀的效果&#xff0c;需要以下几个步骤&#xff1a; 1.1、创建一个类&#xff0c;包含烟花各项粒子的…

解决 Nginx 反向代理中的 DNS 解析问题:从挑战到突破20231228

引言 在使用 Nginx 作为反向代理服务器时&#xff0c;我们可能会遇到各种配置和网络问题。最近&#xff0c;我遇到了一个有趣的挑战&#xff1a;Nginx 在反向代理配置中无法解析特定的域名&#xff0c;导致 502 错误。这个问题的解决过程不仅揭示了 Nginx 的一个不太为人知的功…

力扣刷题记录(20)LeetCode:198、213、337

198. 打家劫舍 我们从第一个开始分析&#xff1a; dp[i]:i表示索引&#xff0c;dp表示当前索引可以拿到的最高金额 索引为0时&#xff0c;可以拿到的最高金额为1&#xff1b; 索引为1时&#xff0c;可以拿到的最高金额就是在索引[0,1]之间取&#xff0c;为2 索引为2时&…

[华为诺亚实验室+中科大提出TinySAM | 比SAM小10倍,精度的超车!]

文章目录 概要整体架构流程Related Work技术细节小结 概要 最近&#xff0c;Segment Anything Model (SAM) 已经展示出了强大的分割能力&#xff0c;在计算机视觉领域引起了广泛关注。基于预训练的 SAM 的大量研究工作已经开发了各种应用&#xff0c;并在下游视觉任务上取得了令…

leaflet学习笔记-自定义Icon(四)

前言 leaflet的marker可以使用icon&#xff0c;所以这篇文章我们自定义一个icon&#xff0c;并在marker中使用&#xff0c;满足我的恶趣味 实例化Icon 首先准备一个你喜欢的图片&#xff0c;并将它添加到你的项目中&#xff0c;这里我找了一张本人的卡通图片 icon实例化代码&…

121. 买卖股票的最佳时机(Java)

给定一个数组 prices &#xff0c;它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票&#xff0c;并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返回你可以从这笔交易中获取的最大利润。…